public async Task Leading_trailing_whitespaces_in_username_are_ignored() { // Given GivenSignInIsSuccessful(); // When await controller.Index(LoginTestHelper.GetDefaultLoginViewModel("\[email protected] ")); // Then A.CallTo(() => loginService.AttemptLogin("*****@*****.**", "testPassword")).MustHaveHappened(1, Times.Exactly); }
public async Task Successful_sign_in_without_return_url_should_render_home_pageAsync() { // Given GivenSignInIsSuccessful(); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeRedirectToActionResult() .WithControllerName("Home").WithActionName("Index"); }
public async Task Invalid_model_should_render_basic_form_with_error() { // Given controller.ModelState.AddModelError(nameof(LoginViewModel.Username), "Required"); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeViewResult().WithViewName("Index").ModelAs <LoginViewModel>(); Assert.IsFalse(controller.ModelState.IsValid); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("Connect")) { LoginTestHelper rpc = target as LoginTestHelper; if (rpc) { rpc.TestConnect(); } } if (GUILayout.Button("Login")) { LoginTestHelper rpc = target as LoginTestHelper; if (rpc) { rpc.TestLogin(); } } if (GUILayout.Button("CharacterList")) { LoginTestHelper rpc = target as LoginTestHelper; if (rpc) { rpc.TestCharacterList(); } } if (GUILayout.Button("SelectCharacter")) { LoginTestHelper rpc = target as LoginTestHelper; if (rpc) { rpc.TestSelectCharacter(); } } if (GUILayout.Button("CreateCharacter")) { LoginTestHelper rpc = target as LoginTestHelper; if (rpc) { rpc.TestCreateCharacter(); } } if (GUILayout.Button("SelectSaveUser")) { LoginTestHelper rpc = target as LoginTestHelper; if (rpc) { rpc.TestSelectSaveUser(); } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("KeyAuth")) { LoginTestHelper rpc = target as LoginTestHelper; if (rpc) { rpc.TestKeyAuth(); } } }
When_user_has_verified_accounts_only_at_inactive_centres_then_redirect_to_centre_inactive_page() { // Given A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.InactiveCentre) ); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeViewResult().WithViewName("CentreInactive"); }
public async Task Unapproved_delegate_account_redirects_to_not_approved_page() { // Given A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.AccountNotApproved) ); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeViewResult().WithViewName("AccountNotApproved"); }
public async Task Bad_password_should_render_basic_form_with_error() { // Given A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.InvalidPassword) ); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeViewResult().WithViewName("Index").ModelAs <LoginViewModel>(); Assert.IsFalse(controller.ModelState.IsValid); }
public async Task Locked_admin_returns_locked_view() { // Given var adminUser = UserTestHelper.GetDefaultAdminUser(failedLoginCount: 6); A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.AccountLocked, adminUser) ); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeRedirectToActionResult().WithActionName("AccountLocked"); }
public async Task Log_in_as_admin_records_admin_session() { // Given var expectedAdmin = UserTestHelper.GetDefaultAdminUser(10); A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.LogIntoSingleCentre, expectedAdmin, new List <DelegateUser>()) ); // When await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then A.CallTo(() => sessionService.StartAdminSession(expectedAdmin.Id)) .MustHaveHappened(); }
public async Task Log_in_as_delegate_does_not_record_admin_session() { // Given var expectedDelegates = new List <DelegateUser> { UserTestHelper.GetDefaultDelegateUser() }; A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.LogIntoSingleCentre, delegateUsers: expectedDelegates) ); // When await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then A.CallTo(() => sessionService.StartAdminSession(A <int> ._)) .MustNotHaveHappened(); }
public async Task Multiple_available_centres_should_redirect_to_ChooseACentre_page() { // Given var expectedAdminUser = UserTestHelper.GetDefaultAdminUser(centreId: 1, centreName: "Centre 1"); var expectedDelegateUsers = new List <DelegateUser> { UserTestHelper.GetDefaultDelegateUser(centreId: 2, centreName: "Centre 2") }; A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.ChooseACentre, expectedAdminUser, expectedDelegateUsers) ); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeRedirectToActionResult().WithActionName("ChooseACentre"); }
public async Task Successful_sign_in_should_call_SignInAsync() { // Given GivenSignInIsSuccessful(); // When await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then A.CallTo( () => authenticationService.SignInAsync( A <HttpContext> ._, A <string> ._, A <ClaimsPrincipal> ._, A <AuthenticationProperties> ._ ) ) .MustHaveHappened(); }
public async Task Successful_sign_in_with_query_string_should_redirect_with_correct_query() { // Given GivenSignInIsSuccessful(); var returnUrl = "/some/other/page?query=true&other=false"; var urlHelper = controller.Url; A.CallTo(() => urlHelper.IsLocalUrl(returnUrl)).Returns(true); var loginViewModel = LoginTestHelper.GetDefaultLoginViewModel(); loginViewModel.ReturnUrl = returnUrl; // When var result = await controller.Index(loginViewModel); // Then result.Should().BeRedirectResult().WithUrl(returnUrl); }
public async Task Multiple_approved_accounts_at_same_centre_should_log_in() { // Given var expectedAdminUser = UserTestHelper.GetDefaultAdminUser(centreId: 1, centreName: "Centre 1"); var expectedDelegateUsers = new List <DelegateUser> { UserTestHelper.GetDefaultDelegateUser(centreId: 1, centreName: "Centre 1", approved: true) }; A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns( new LoginResult(LoginAttemptResult.LogIntoSingleCentre, expectedAdminUser, expectedDelegateUsers) ); // When var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel()); // Then result.Should().BeRedirectToActionResult() .WithControllerName("Home").WithActionName("Index"); }
public async Task Successful_sign_in_with_nonlocal_return_url_should_render_home_page() { // Given GivenSignInIsSuccessful(); var returnUrl = "www.suspicious.com"; var urlHelper = controller.Url; A.CallTo(() => urlHelper.IsLocalUrl(returnUrl)).Returns(false); // When var loginViewModel = LoginTestHelper.GetDefaultLoginViewModel(); loginViewModel.ReturnUrl = returnUrl; var result = await controller.Index(loginViewModel); // Then result.Should().BeRedirectToActionResult() .WithControllerName("Home").WithActionName("Index"); }