Asp.net web api Can';t Mock HttpContext.GetOwinContext()
我正在尝试在登录中实现Auth0 Asp.Net OWIN 我在AccountController上进行单元测试,问题是HTTPContext总是空的 有没有关于如何模拟HttpContext来测试登录名的建议Asp.net web api Can';t Mock HttpContext.GetOwinContext(),asp.net-web-api,owin,auth0,httpcontext,webapi,Asp.net Web Api,Owin,Auth0,Httpcontext,Webapi,我正在尝试在登录中实现Auth0 Asp.Net OWIN 我在AccountController上进行单元测试,问题是HTTPContext总是空的 有没有关于如何模拟HttpContext来测试登录名的建议 public class AccountController : Controller { public ActionResult Login(string returnUrl) { HttpContext.GetOwinContext().Authent
public class AccountController : Controller
{
public ActionResult Login(string returnUrl)
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties
{
RedirectUri = returnUrl ?? Url.Action("Index", "Home")
},
"Auth0");
return new HttpUnauthorizedResult();
}
[Authorize]
public void Logout()
{
HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
HttpContext.GetOwinContext().Authentication.SignOut("Auth0");
}
[Authorize]
public ActionResult Claims()
{
return View();
}
}