如何在 xUnit 中模拟和读取 cookie? [英] How to mock and read a cookie in xUnit?

查看:38
本文介绍了如何在 xUnit 中模拟和读取 cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法.在那,我正在阅读下面的cookie,

I have a method. In that, I am reading the cookie like below,

string cookieData = Request.Cookies["XXXX"];

问题是在编写 xUnit 时我得到了一个空值.任何人都可以帮助我如何做到这一点?

the issue is while writing a xUnit I am getting a null. Can anyone please help me with how to do this?

推荐答案

您应该在代码和读取 cookie 之间添加一个外观.然后你可以从外观模拟结果.IE _myCookieFacade.Request("NameOfCookie)

You should add a facade between your code and the reading of the cookie. Then you can mock the result from the facade. IE _myCookieFacade.Request("NameOfCookie)

这篇关于如何在 xUnit 中模拟和读取 cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆