도와주세요 내 정적 클래스
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();
}
}
처럼
내 컨트롤러 방법이 보인다 의존. 단위 테스트는 .net 프레임 워크가 아닌 코드를 테스트해야합니다.
유효한 테스트는 실제로 Session.Clear를 테스트하지 않고 Session.Clear에 대한 호출이 발생했는지 확인하는 것일 수 있습니다. 세션을 지우는 것이 좋습니다.
가짜 세션을 설정하면됩니다. 다음은 단위 테스트를 위해 컨트롤러 컨텍스트를 설정하는 데 사용하는 확장 메서드입니다.
public static void SetControllerContext (이 컨트롤러 컨트롤러) { var fakeContext = A.Fake(); var fakeRequest = A.Fake(); var fakeResponse = A.Fake(); var fakeSessionState = A.Fake();
A.CallTo(() => fakeRequest.HttpMethod).Returns(HttpVerbs.Post.ToString());
A.CallTo(() => fakeContext.Response).Returns(fakeResponse);
A.CallTo(() => fakeContext.Request).Returns(fakeRequest);
A.CallTo(() => fakeContext.Session).Returns(fakeSessionState);
var fakeRequestContext = new RequestContext(fakeContext, new RouteData());
controller.ControllerContext = new ControllerContext(fakeRequestContext, controller);
}
이것은 FakeItEasy를 사용하지만 Moq에서도 동일한 작업을 수행 할 수 있습니다.
MS "ASP.NET 세션 상태를 사용하면 사용자가 웹 응용 프로그램의 ASP.NET 페이지를 탐색 할 때 사용자 값을 저장하고 검색 할 수 있습니다."
정적 클래스에서 값을 배치 할 때의 가치는 무엇입니까?