Y
Y
YoppaLotus2019-11-15 14:44:54
ASP.NET
YoppaLotus, 2019-11-15 14:44:54

How to use cookies in xUnit?

I wrote an Action of some controller, as well as a test for it. The problem is that the Action uses the value from the cookie, and the test, when trying to execute this Action, throws an error System.NullReferenceException : Object reference not set to an instance of an object. on the line with cookies. How can I write a test for my Action without changing it, and does this mean that I'm doing something wrong and my application architecture is bad?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YoppaLotus, 2019-11-15
@YoppaLotus

controller.Response.Cookies.Append("Company", new Mock<string>().Object);

It's done like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question