public void MyTestInitialize() { using (ShimsContext.Create()) { // Set up _stubForSingleConcurrentLoginRules = new StubISingleConcurrentLoginRules { InstanceObserver = new StubObserver() }; _stubForIErrorLoggingService = new StubIErrorLoggingService() { InstanceObserver = new StubObserver() }; _stubForISIMPLSessionEntitiesRepository = new StubISIMPLSessionEntitiesRepository { InstanceObserver = new StubObserver() }; _mySingleConcurrentLoginManager = new SingleConcurrentLoginManager(_stubForSingleConcurrentLoginRules, _stubForIErrorLoggingService, _stubForISIMPLSessionEntitiesRepository); } }
public void MyTestInitialize() { using (ShimsContext.Create()) { // Set up the LoginControllerForTests LoginControllerForTests = DependencyResolver.Current.GetService<LoginController>(); // Set up the LoginViewModelForTests var logout = new Logout(); var myErrorLoggingService = new ErrorLoggingService(); var mySingleConcurrentLoginRules = new SingleConcurrentLoginRules(); var mySIMPLSessionEntitiesRepository = new SIMPLSessionEntitiesRepository(myErrorLoggingService); var mySingleConConcurrentLoginManager = new SingleConcurrentLoginManager(mySingleConcurrentLoginRules, myErrorLoggingService, mySIMPLSessionEntitiesRepository); LoginViewModelForTests = new LoginViewModel(logout, myErrorLoggingService, mySingleConcurrentLoginRules, mySingleConConcurrentLoginManager, mySIMPLSessionEntitiesRepository); ConfigControllerForTests = DependencyResolver.Current.GetService<ConfigController>(); } }
public void CreateLoginRecord_throws_exception_when_mySIMPLSessionEntitiesRepository_argument_in_constructor_is_null() { Exception expectedException = null; const string expectedExceptionMessage = "Parameter is null\r\nParameter name: _mySIMPLSessionEntitiesRepository"; const string userName = "******"; const string sessionId = "doesNotMatter"; // Given a null for _mySIMPLSessionEntitiesRepository SIMPLSessionEntitiesRepository _mySIMPLSessionEntitiesRepository = null; // overriding the _mySingleConcurrentLoginManager with a specific case for this test _mySingleConcurrentLoginManager = new SingleConcurrentLoginManager(_stubForSingleConcurrentLoginRules, _stubForIErrorLoggingService, _mySIMPLSessionEntitiesRepository); var wasCreateSIMPLLoginTrackerRecordCalled = false; var wasAddSIMPLLoginTrackerRecordToCacheCalled = false; // As all of the methods in the SIMPLSessionEntitiesCache class are static, don't have an interface and cannot use stubs - so we have to use shims here // Also, since we are not calling the stub for SIMPLSessionEntitiesRepository, need to shim that too using (ShimsContext.Create()) { // And AddSIMPLLoginTrackerRecordToCache is not called ShimSIMPLSessionEntitiesCache.AddSIMPLLoginTrackerRecordToCacheStringSIMPLLoginTracker = (userNameValue, myLoginTrackerValue) => { wasAddSIMPLLoginTrackerRecordToCacheCalled = true; return false; }; ShimSIMPLSessionEntitiesRepository.AllInstances.CreateSIMPLLoginTrackerRecordStringString = (methodName, userNameValue, sessionIdValue) => { wasCreateSIMPLLoginTrackerRecordCalled = true; return null; }; // When calling CreateLoginRecord try { _mySingleConcurrentLoginManager.CreateLoginRecord(userName, sessionId); } catch (Exception ex) { // Then an exception is thrown expectedException = ex; } } Assert.IsNotNull(expectedException); Assert.IsTrue(expectedException is ArgumentException, "expectedException is not an ArgumentException"); Assert.AreEqual(expectedExceptionMessage, expectedException.Message, "Exception Message doesn't match expected value"); var myMicrosoftFakesTestHelper = new MicrosoftFakesTestHelper(); // And IsCheckEnabled is not called var wasIsCheckEnabledCalled = myMicrosoftFakesTestHelper.WasMethodCalled(_stubForSingleConcurrentLoginRules, "IsCheckEnabled"); Assert.IsFalse(wasIsCheckEnabledCalled, "wasIsCheckEnabledCalled is true"); // And CreateSIMPLLoginTrackerRecord is not called Assert.IsFalse(wasCreateSIMPLLoginTrackerRecordCalled, "wasCreateSIMPLLoginTrackerRecordCalled is true"); // And AddSIMPLLoginTrackerRecordToCache is not called Assert.IsFalse(wasAddSIMPLLoginTrackerRecordToCacheCalled, "wasAddSIMPLLoginTrackerRecordToCacheCalled is true"); }