Example #1
0
        public async Task CanChangeEmail()
        {
            // Arrange
            var emails = new ContosoEmailSender();

            void ConfigureTestServices(IServiceCollection services) =>
            services.SetupTestEmailSender(emails);

            var server = ServerFactory
                         .WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));
            var client       = server.CreateClient();
            var newClient    = server.CreateClient();
            var failedClient = server.CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"[PLACEHOLDER]-1a";
            var newEmail = "*****@*****.**";

            var index = await UserStories.RegisterNewUserAsync(client, userName, password);

            var email = await UserStories.SendUpdateEmailAsync(index, newEmail);

            // Act & Assert
            Assert.Equal(2, emails.SentEmails.Count);
            await UserStories.ConfirmEmailAsync(emails.SentEmails[1], client);

            // Verify can login with new email, fails with old
            await UserStories.LoginExistingUserAsync(newClient, newEmail, password);

            await UserStories.LoginFailsWithWrongPasswordAsync(failedClient, userName, password);
        }