Below is the method in my controller,
public IActionResult Cookiewrite(string key, string value)
{
CookieOptions options = new CookieOptions();
options.Expires = DateTime.Now.AddHours(1);
HttpContext.Response.Cookies.Append(key, value, options);
return View("Cookiewrite");
}
I am trying to do the test using xUnit, Like below.
[Fact]
public void CookieWriteTest()
{
string key = "xxxx";
string value = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var result = homeController.Cookiewrite(key, value);
}
but the issue I am getting null error while setting the cookie (Microsoft.AspNetCore.Mvc.ControllerBase.HttpContext.get returned null.). Can anyone please help me with how to do this. as I am new to xUnit.