public void LogUserOutIfConditionsAreMetActor_returns_false_when_Session_does_not_have_username() { // Set up // And ShouldLogUserOut is not called var wasShouldLogUserOutCalled = false; var result = false; using (ShimsContext.Create()) { // Given an application that is HttpApplication with Context and Session (just enough Session to move forward) var session = new ShimHttpSessionState(); var context = new ShimHttpContext { SessionGet = () => session }; var app = new ShimHttpApplication { ContextGet = () => context }; ShimSingleConcurrentLoginManager.AllInstances.ShouldLogUserOutStringString = (method, usernameValue, sessionIdValue) => { wasShouldLogUserOutCalled = true; return true; }; // When calling LogUserOutIfConditionsAreMetActor result = _mySingleConcurrentLoginManager.LogUserOutIfConditionsAreMetActor(app); } // Then there is a return of false Assert.IsFalse(result, "LogUserOutIfConditionsAreMetActor returned true"); var myMicrosoftFakesTestHelper = new MicrosoftFakesTestHelper(); // And IsCheckEnabled is not called var wasIsCheckEnabledCalled = myMicrosoftFakesTestHelper.WasMethodCalled(_stubForSingleConcurrentLoginRules, "IsCheckEnabled"); Assert.IsTrue(wasIsCheckEnabledCalled, "wasIsCheckEnabledCalled is false"); // And ShouldLogUserOut is not called Assert.IsFalse(wasShouldLogUserOutCalled, "wasShouldLogUserOutCalled is true"); }
public void LogUserOutIfConditionsAreMetActor_returns_true_when_ShouldLogUserOut_returns_true() { // Set up _stubForSingleConcurrentLoginRules.IsCheckEnabled = () => true; // And ShouldLogUserOut is not called var wasShouldLogUserOutCalled = false; bool result; using (ShimsContext.Create()) { // Given an application that is HttpApplication with Context and Session with username var session = new ShimHttpSessionState { ItemGetString = s => { if (s == "username") { return "usernameValue"; } return null; }, SessionIDGet = () => "sessionIdValue" }; var context = new ShimHttpContext { SessionGet = () => session }; var app = new ShimHttpApplication { ContextGet = () => context }; ShimSingleConcurrentLoginManager.AllInstances.ShouldLogUserOutStringString = (method, usernameValue, sessionIdValue) => { wasShouldLogUserOutCalled = true; return true; }; // When calling LogUserOutIfConditionsAreMetActor result = _mySingleConcurrentLoginManager.LogUserOutIfConditionsAreMetActor(app); } // Then there is a return of true Assert.IsTrue(result, "LogUserOutIfConditionsAreMetActor returned false"); var myMicrosoftFakesTestHelper = new MicrosoftFakesTestHelper(); // And IsCheckEnabled is not called var wasIsCheckEnabledCalled = myMicrosoftFakesTestHelper.WasMethodCalled(_stubForSingleConcurrentLoginRules, "IsCheckEnabled"); Assert.IsTrue(wasIsCheckEnabledCalled, "wasIsCheckEnabledCalled is false"); // And ShouldLogUserOut is not called Assert.IsTrue(wasShouldLogUserOutCalled, "wasShouldLogUserOutCalled is false"); }
public void LogUserOutIfConditionsAreMetActor_returns_false_application_is_HttpApplication_with_Context_but_Session_is_null() { // And IsCheckEnabled is not called var wasIsCheckEnabledCalled = false; // And ShouldLogUserOut is not called var wasShouldLogUserOutCalled = false; var result = false; using (ShimsContext.Create()) { // Given a sender that is HttpApplication with Context but Session is null var context = new ShimHttpContext { SessionGet = () => null }; var app = new ShimHttpApplication { ContextGet = () => context }; ShimSingleConcurrentLoginManager.AllInstances.ShouldLogUserOutStringString = (method, usernameValue, sessionIdValue) => { wasShouldLogUserOutCalled = true; return true; }; // When calling LogUserOutIfConditionsAreMetActor result = _mySingleConcurrentLoginManager.LogUserOutIfConditionsAreMetActor(app); } // Then there is a return of false Assert.IsFalse(result, "LogUserOutIfConditionsAreMetActor returned true"); // And IsCheckEnabled is not called Assert.IsFalse(wasIsCheckEnabledCalled, "wasIsCheckEnabledCalled is true"); // And ShouldLogUserOut is not called Assert.IsFalse(wasShouldLogUserOutCalled, "wasShouldLogUserOutCalled is true"); }