public async Task AddUser_AfterAdded_Success() { AddUserService addUserService = new AddUserService( UserManagerMock.Create().WithCreateSuccess().Object, SignInManagerMock.Create().Object, IEmailConfirmationServiceMock.Create().SendVerificationMailSuccess().Object, IGroupUserServiceMock.Create().Object, IAddUserFilterMock.Create().BeforeAdd_Success().AfterAdded_Success().Object, IBaseDAOMock<AppUserEntity>.Create().Object, IBaseDAOMock<InviteEntity>.Create().Object, IBaseDAOMock<RoleEntity>.Create().Object, IOptionsMock<IdentityUIEndpoints>.Create().DefaultValue().Object, IValidatorMock<NewUserRequest>.Create().Object, IValidatorMock<RegisterRequest>.Create().Object, IValidatorMock<AcceptInviteRequest>.Create().Object, IValidatorMock<ExternalLoginRegisterRequest>.Create().Object, IValidatorMock<GroupBaseUserRegisterRequest>.Create().Object, IValidatorMock<BaseRegisterRequest>.Create().Validate_Valid().Object, IValidatorMock<IUserAttributeRequest>.Create().Validate_Valid().Object, NullLogger<AddUserService>.Instance); BaseRegisterRequest baseRegisterRequest = new Fixture() .Build<BaseRegisterRequest>() .Create(); Result<AppUserEntity> result = await addUserService.AddUser(baseRegisterRequest); result.Success.Should().BeTrue(); }
public async void Logout_HappyPath() { // Act await AccountController.Logout(); // Assert SignInManagerMock.Verify(x => x.SignOutAsync(), Times.Once); }
public async Task Valid_Login() { UserManagerMock.Setup(m => m.FindByEmailAsync(It.IsAny <string>())).ReturnsAsync(new IdentityUser()); SignInManagerMock.Setup(m => m.SignOutAsync()); SignInManagerMock.Setup(m => m.PasswordSignInAsync(It.IsAny <IdentityUser>(), It.IsAny <string>(), false, false)) .ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success); var target = new AccountController(UserManagerMock.Object, SignInManagerMock.Object, PasswordValidatorMock.Object); var result = await target.Login(new UserInfoViewModel(), "returnUrl") as RedirectResult; Assert.NotNull(result); Assert.Equal("returnUrl", result.Url); }
public async Task Invalid_Password_Or_User_Name_Login() { UserManagerMock.Setup(m => m.FindByEmailAsync(It.IsAny <string>())).ReturnsAsync(new IdentityUser()); SignInManagerMock.Setup(m => m.SignOutAsync()); SignInManagerMock.Setup(m => m.PasswordSignInAsync(It.IsAny <IdentityUser>(), It.IsAny <string>(), false, false)) .ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Failed); var target = new AccountController(UserManagerMock.Object, SignInManagerMock.Object, PasswordValidatorMock.Object); var result = await target.Login(new UserInfoViewModel(), "returnUrl") as ViewResult; Assert.NotNull(result); Assert.Equal(1, target.ModelState.ErrorCount); }
public void Refresh_token_succeeds_for_existing_user() { // Arrange var user = new User() { Id = "userId", Email = "email", Username = "******", PasswordHash = "password" }; var signInManager = new SignInManagerMock(); signInManager.SetupForUser(user); var tokenService = new TokenServiceMock(); tokenService.SetupTokenBuild(u => u.Id + "_token"); var logger = new ConsoleLoggerMock <Services.AuthenticationService>(); var userManager = new UserManagerMock(); userManager.SetupExistingUser(user); var eventBus = new EventPublisherMock(); var confirmationSender = new EmailConfirmationSenderMock(); var service = new Services.AuthenticationService( userManager.Object, signInManager.Object, tokenService.Object, eventBus.Object, logger.Object, confirmationSender.Object); // Act OperationResult <JwtToken> result = service.RefreshToken("userId").Result; // Assert Assert.True(result.IsValid); Assert.AreEqual("userId_token", result.Result.Token); }
public void Login_HappyPath() { // Arrange const string username = "******"; const string password = "******"; var loginModel = new LoginViewModel { UserName = username, Password = password, RememberMe = true }; string returnUrl = string.Empty; var identityUser = new IdentityUser(); UserClientMock.Setup(client => client.AuthenticateUser(username, password)).Returns(identityUser); // Act ActionResult result = AccountController.Login(loginModel, returnUrl).Result; // Assert SignInManagerMock.Verify(x => x.SignInAsync(identityUser, true, true)); result.Should().NotBeNull(); }
private void AssertNeverSignedIn() { SignInManagerMock.Verify(x => x.SignInAsync(It.IsAny <IdentityUser>(), It.IsAny <bool>(), It.IsAny <bool>()), Times.Never); }