Пример #1
0
        public async Task CanLogInAfterConfirmingEmail()
        {
            // Arrange
            TestEmailSender testEmailSender = new TestEmailSender();
            var             server          = ServerFactory.CreateServer(builder =>
            {
                builder.ConfigureServices(services => services
                                          .AddSingleton <IEmailSender>(testEmailSender)
                                          .Configure <IdentityOptions>(opt => opt.SignIn.RequireConfirmedEmail = true));
            });

            var client    = ServerFactory.CreateDefaultClient(server);
            var newClient = ServerFactory.CreateDefaultClient(server);

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"!Test.Password1$";

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

            // Act & Assert
            // Use a new client to simulate a new browser session.
            var emailBody   = HtmlAssert.IsHtmlFragment(testEmailSender.HtmlMessage);
            var linkElement = HtmlAssert.HasElement("a", emailBody);
            var link        = Assert.IsAssignableFrom <IHtmlAnchorElement>(linkElement);
            var response    = await newClient.GetAsync(link.Href);

            await UserStories.LoginExistingUserAsync(newClient, userName, password);
        }
Пример #2
0
        public async Task CannotLogInWithoutRequiredEmailConfirmation()
        {
            // Arrange
            var testEmailSender = new TestEmailSender();
            var server          = ServerFactory.CreateServer(builder =>
            {
                builder.ConfigureServices(services => services
                                          .AddSingleton <IEmailSender>(testEmailSender)
                                          .Configure <IdentityOptions>(opt => opt.SignIn.RequireConfirmedEmail = true));
            });

            var client    = ServerFactory.CreateDefaultClient(server);
            var newClient = ServerFactory.CreateDefaultClient(server);

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"!Test.Password1$";

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

            // Act & Assert
            // Use a new client to simulate a new browser session.
            await Assert.ThrowsAnyAsync <XunitException>(() => UserStories.LoginExistingUserAsync(newClient, userName, password));
        }