【发布时间】:2016-11-18 08:37:57
【问题描述】:
我在 .Net Core 1.1 框架上用 ASP.Net Core 编写了这个小方法:
public class AccountController : Controller
{
public IActionResult Logout()
{
HttpContext.Authentication.SignOutAsync("SchemaName");
HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return RedirectToAction("Index", "Home");
}
}
我在如何编写一个单元测试来验证此方法是否返回 RedirectToActionResult 并尝试了许多不同的方法,这些方法基于在这里和那里找到的旧信息和相对新信息。问题是HttpContext 是null,我一直没有成功地模拟它。
对于编写此测试的任何帮助将不胜感激!
【问题讨论】:
标签: c# unit-testing asp.net-core-mvc .net-core