Exemplo n.º 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);
        }
Exemplo n.º 2
0
        internal static async Task <ResetPasswordConfirmation> ResetPasswordAsync(HttpClient client, IdentityEmail resetPasswordEmail, string email, string newPassword)
        {
            var emailBody   = HtmlAssert.IsHtmlFragment(resetPasswordEmail.Body);
            var linkElement = HtmlAssert.HasElement("a", emailBody);
            var link        = Assert.IsAssignableFrom <IHtmlAnchorElement>(linkElement);

            var resetPassword = await ResetPassword.CreateAsync(link, client, new DefaultUIContext().WithExistingUser());

            return(await resetPassword.SendNewPasswordAsync(email, newPassword));
        }
Exemplo n.º 3
0
        internal static async Task <ConfirmEmail> ConfirmEmailAsync(IdentityEmail email, HttpClient client)
        {
            var emailBody   = HtmlAssert.IsHtmlFragment(email.Body);
            var linkElement = HtmlAssert.HasElement("a", emailBody);
            var link        = Assert.IsAssignableFrom <IHtmlAnchorElement>(linkElement);

            return(await ConfirmEmail.Create(link, client, new DefaultUIContext()
                                             .WithAuthenticatedUser()
                                             .WithExistingUser()
                                             .WithConfirmedEmail()));
        }
Exemplo n.º 4
0
 public Index(HttpClient client, IHtmlDocument index, HtmlPageContext context, bool authenticated)
     : base(client, index, context)
 {
     _authenticated = authenticated;
     if (!_authenticated)
     {
         _registerLink = HtmlAssert.HasLink("#register", Document);
         _loginLink    = HtmlAssert.HasLink("#login", Document);
     }
     else
     {
         _manageLink = HtmlAssert.HasLink("#manage", Document);
     }
 }
Exemplo n.º 5
0
 public RegisterConfirmation(
     HttpClient client,
     IHtmlDocument register,
     DefaultUIContext context)
     : base(client, register, context)
 {
     if (Context.HasRealEmailSender)
     {
         Assert.Empty(Document.QuerySelectorAll("#confirm-link"));
     }
     else
     {
         _confirmLink = HtmlAssert.HasLink("#confirm-link", Document);
     }
 }
Exemplo n.º 6
0
 public Index(
     HttpClient client,
     IHtmlDocument index,
     DefaultUIContext context)
     : base(client, index, context)
 {
     if (!Context.UserAuthenticated)
     {
         _registerLink = HtmlAssert.HasLink("#register", Document);
         _loginLink    = HtmlAssert.HasLink("#login", Document);
     }
     else
     {
         _manageLink = HtmlAssert.HasLink("#manage", Document);
     }
 }