简体   繁体   中英

How to mock and read a cookie in xUnit?

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

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM