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 Users_email_can_be_changed() { // Arrange var user = new User() { Id = "userId", Email = "*****@*****.**", EmailConfirmed = true, PasswordHash = "password", Username = "******" }; var userManager = new UserManagerMock(); userManager.SetupExistingUser(user); var tokenService = new TokenServiceMock(); tokenService.SetupTokenBuild(u => u.Id + "_token"); var logger = new ConsoleLoggerMock <AccountService>(); var confirmationSender = new EmailConfirmationSenderMock(); var emailConfirmationService = new EmailConfirmationServiceMock(); emailConfirmationService.SetupConfirmEmailFor(user, "userId_token"); var service = new AccountService( userManager.Object, emailConfirmationService.Object, confirmationSender.Object, tokenService.Object, logger.Object); // Act OperationResult result = service.ChangeEmail("userId", "*****@*****.**", "password").Result; // Assert Assert.True(result.IsValid); Assert.AreEqual("*****@*****.**", user.Email); }
public void Email_confirmation_can_be_resent() { // Arrange var user = new User() { Id = "userId", Email = "*****@*****.**", EmailConfirmed = false, PasswordHash = "password", Username = "******" }; var userManager = new UserManagerMock(); userManager.SetupExistingUser(user); var tokenService = new TokenServiceMock(); tokenService.SetupTokenBuild(u => u.Id + "_token"); var logger = new ConsoleLoggerMock <AccountService>(); var confirmationSender = new EmailConfirmationSenderMock(); var emailConfirmationService = new EmailConfirmationServiceMock(); emailConfirmationService.SetupConfirmEmailFor(user, "userId_token"); var service = new AccountService( userManager.Object, emailConfirmationService.Object, confirmationSender.Object, tokenService.Object, logger.Object); // Act OperationResult result = service.ResendConfirmationEmail("*****@*****.**", "password").Result; // Assert Assert.True(result.IsValid); confirmationSender.VerifyEmailSent("username", "*****@*****.**"); }
public void After_confirm_email_call_users_email_is_confirmed() { // Arrange var user = new User() { Id = "userId", Email = "*****@*****.**", EmailConfirmed = false }; var userManager = new UserManagerMock(); userManager.SetupExistingUser(user); var tokenService = new TokenServiceMock(); tokenService.SetupTokenBuild(u => u.Id + "_token"); var logger = new ConsoleLoggerMock <AccountService>(); var confirmationSender = new EmailConfirmationSenderMock(); var emailConfirmationService = new EmailConfirmationServiceMock(); emailConfirmationService.SetupConfirmEmailFor(user, "userId_token"); var service = new AccountService( userManager.Object, emailConfirmationService.Object, confirmationSender.Object, tokenService.Object, logger.Object); // Act OperationResult result = service.ConfirmEmail("userId", "userId_token").Result; // Assert Assert.True(result.IsValid); Assert.True(user.EmailConfirmed); }
public void Register_creates_user_publishes_event_and_sends_email() { // Arrange ISignInManager signInManager = Mock.Of <ISignInManager>(); ITokenService tokenService = Mock.Of <ITokenService>(); var logger = new ConsoleLoggerMock <Services.AuthenticationService>(); var userManager = new UserManagerMock(); var eventBus = new EventPublisherMock(); var confirmationSender = new EmailConfirmationSenderMock(); var service = new Services.AuthenticationService( userManager.Object, signInManager, tokenService, eventBus.Object, logger.Object, confirmationSender.Object); // Act OperationResult result = service.RegisterUser("username", "email", "password").Result; // Assert Assert.True(result.IsValid); userManager.VerifyUserCreated("username", "email", "password"); eventBus.VerifyEventPublished <UserRegisteredEvent, UserInfo>(u => u.Username == "username" && u.Email == "email"); confirmationSender.VerifyEmailSent("username", "email"); }