public void Correctly_provides_feedback_if_login_is_unsuccessful() { MockRepository mocks = new MockRepository(); ILoginChecker checker = mocks.CreateMock<ILoginChecker>(); IAuthenticationService authenticationService = mocks.CreateMock<IAuthenticationService>(); ISystemUserRepository repository = mocks.CreateMock<ISystemUserRepository>(); using (mocks.Record()) { Expect.Call(checker.IsValidUser("*****@*****.**", "pass", repository)).Return(false); } using (mocks.Playback()) { ILoginService loginService = new LoginService(checker, authenticationService, null); string userFeedback = loginService.Login("*****@*****.**", "pass", false, repository); Assert.That(userFeedback, Is.EqualTo("Invalid e-mail address/password: Please try again")); } mocks.VerifyAll(); }
public void Correctly_logs_users_out_and_redirects_them_to_the_login_page() { MockRepository mocks = new MockRepository(); IWebContext context = mocks.CreateMock<IWebContext>(); IAuthenticationService authenticationService = mocks.CreateMock<IAuthenticationService>(); using (mocks.Record()) { authenticationService.Logout(); Expect.Call(authenticationService.GetLoginUrl()).Return("Login.aspx"); context.Redirect("Login.aspx"); } using (mocks.Playback()) { ILoginService loginService = new LoginService(null, authenticationService, context); loginService.Logout(); } mocks.VerifyAll(); }
public void Correctly_redirects_from_login_page_when_valid_login_is_entered() { MockRepository mocks = new MockRepository(); ILoginChecker checker = mocks.CreateMock<ILoginChecker>(); IAuthenticationService authenticationService = mocks.CreateMock<IAuthenticationService>(); ISystemUserRepository repository = mocks.CreateMock<ISystemUserRepository>(); using (mocks.Record()) { Expect.Call(checker.IsValidUser("*****@*****.**", "pass", repository)).Return(true); authenticationService.RedirectFromLoginPage("*****@*****.**", true); } using (mocks.Playback()) { ILoginService loginService = new LoginService(checker, authenticationService, null); string userFeedback = loginService.Login("*****@*****.**", "pass", true, repository); Assert.That(userFeedback, Is.Null); } mocks.VerifyAll(); }