public async Task CanLogInAfterResettingThePassword() { using (StartLog(out var loggerFactory)) { // Arrange var emailSender = new ContosoEmailSender(); var server = ServerFactory.CreateServer(loggerFactory, b => b.ConfigureServices(s => s.SetupTestEmailSender(emailSender))); var client = ServerFactory.CreateDefaultClient(server); var resetPasswordClient = ServerFactory.CreateDefaultClient(server); var newClient = ServerFactory.CreateDefaultClient(server); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"!Test.Password1$"; var newPassword = $"!New.Password1$"; await UserStories.RegisterNewUserAsync(client, userName, password); var registrationEmail = Assert.Single(emailSender.SentEmails); await UserStories.ConfirmEmailAsync(registrationEmail, client); // Act & Assert await UserStories.ForgotPasswordAsync(resetPasswordClient, userName); Assert.Equal(2, emailSender.SentEmails.Count); var email = emailSender.SentEmails[1]; await UserStories.ResetPasswordAsync(resetPasswordClient, email, userName, newPassword); await UserStories.LoginExistingUserAsync(newClient, userName, newPassword); } }
public async Task CanResetPassword_WithGlobalAuthorizeFilter() { // Arrange var emailSender = new ContosoEmailSender(); void ConfigureTestServices(IServiceCollection services) => services.SetupGlobalAuthorizeFilter().SetupTestEmailSender(emailSender); var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices)); var client = server.CreateClient(); var resetPasswordClient = server.CreateClient(); var newClient = server.CreateClient(); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"[PLACEHOLDER]-1a"; var newPassword = $"[PLACEHOLDER]-1a-updated"; await UserStories.RegisterNewUserAsync(client, userName, password); var registrationEmail = Assert.Single(emailSender.SentEmails); await UserStories.ConfirmEmailAsync(registrationEmail, client); // Act & Assert await UserStories.ForgotPasswordAsync(resetPasswordClient, userName); Assert.Equal(2, emailSender.SentEmails.Count); var email = emailSender.SentEmails[1]; await UserStories.ResetPasswordAsync(resetPasswordClient, email, userName, newPassword); await UserStories.LoginExistingUserAsync(newClient, userName, newPassword); }
public async Task CanLogInAfterResettingThePassword() { // Arrange var emailSender = new ContosoEmailSender(); void ConfigureTestServices(IServiceCollection services) => services .SetupTestEmailSender(emailSender); var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices)); ServerFactory.EnsureDatabaseCreated(); var client = server.CreateClient(); var resetPasswordClient = server.CreateClient(); var newClient = server.CreateClient(); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"!Test.Password1$"; var newPassword = $"!New.Password1$"; await UserStories.RegisterNewUserAsync(client, userName, password); var registrationEmail = Assert.Single(emailSender.SentEmails); await UserStories.ConfirmEmailAsync(registrationEmail, client); // Act & Assert await UserStories.ForgotPasswordAsync(resetPasswordClient, userName); Assert.Equal(2, emailSender.SentEmails.Count); var email = emailSender.SentEmails[1]; await UserStories.ResetPasswordAsync(resetPasswordClient, email, userName, newPassword); await UserStories.LoginExistingUserAsync(newClient, userName, newPassword); }