【发布时间】:2017-06-14 07:13:36
【问题描述】:
如何测试清除会话和注销用户的方法。
我的控制器方法看起来像
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
SessionAdapter.Clear();
SessionAdapter.Abandon();
AuthenticationManager.SignOut
(DefaultAuthenticationTypes.ApplicationCookie);
return RedirectToAction("Index", "Home");
}
这里的会话适配器是我的静态类
public static class SessionAdapter
{
private static string sessionKey = "sessionInfoKey";
public static SessionInfo Instance
{
get
{
return HttpContext.Current.Session[sessionKey] == null ? null : (SessionInfo)HttpContext.Current.Session[sessionKey];
}
set
{
HttpContext.Current.Session[sessionKey] = value;
}
}
public static bool DoesSessionExists { get { return HttpContext.Current.Session[sessionKey] == null ? false : true; } }
public static void Clear()
{
HttpContext.Current.Session.Clear();
}
}
请帮帮我
【问题讨论】:
标签: c# asp.net-mvc unit-testing nunit moq