コード例 #1
0
        public async Task UserLockedOut_AfterMaxFailedAccessAttempts_WithGlobalAuthorizeFilter()
        {
            // Arrange
            var emailSender = new ContosoEmailSender();

            void ConfigureTestServices(IServiceCollection services) =>
            services.SetupGlobalAuthorizeFilter().SetupMaxFailedAccessAttempts().SetupTestEmailSender(emailSender);

            var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));

            var client    = server.CreateClient();
            var newClient = server.CreateClient();

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

            await UserStories.RegisterNewUserAsync(client, userName, password);

            var registrationEmail = Assert.Single(emailSender.SentEmails);
            await UserStories.ConfirmEmailAsync(registrationEmail, client);

            // Act & Assert
            await UserStories.LockoutExistingUserAsync(newClient, userName, wrongPassword);
        }