コード例 #1
0
        public async Task ForgotPassword_Cancel()
        {
            string cancelUrl  = null;
            string confirmUrl = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                EmailTemplates.UserAccountRecover,
                "alice@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = TestServerBuilderExtensions
                                .CreateServer(emailServiceMock);

            HttpClient client = server.CreateClient();

            // Call cancel url
            await client.RecoveryCancelGetValidAsync(cancelUrl);

            // Calling cancel url again shouldnt be possible
            await client.RecoveryCancelGetInvalidAsync(cancelUrl);

            // Calling confirm url shouldnt be possible after successfull
            // cancelation
            await client.RecoveryConfirmGetInvalidAsync(confirmUrl);
        }
コード例 #2
0
        public async Task Try_Recover_Without_ReturnUrl()
        {
            TestServer          server   = TestServerBuilderExtensions.CreateServer();
            HttpClient          client   = server.CreateClient();
            HttpResponseMessage response = await client.GetAsync($"/recover");

            response.StatusCode.Should().Be(HttpStatusCode.Redirect);
            response.Headers.Location.ToString().Should().StartWith("/error");
        }
コード例 #3
0
        public async Task Get_LandingPage()
        {
            TestServer server = TestServerBuilderExtensions.CreateServer();

            HttpClient          client   = server.CreateClient();
            HttpResponseMessage response = await client.GetAsync("/");

            response.StatusCode.Should()
            .BeEquivalentTo(System.Net.HttpStatusCode.NotFound);
        }
コード例 #4
0
        public async Task Get_LandingPage()
        {
            TestServer server = TestServerBuilderExtensions.CreateServer();

            HttpClient          client   = server.CreateClient();
            HttpResponseMessage response = await client.GetAsync("/");

            string html = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();
        }
コード例 #5
0
        public async Task ForgotPassword_Confirm_AddNewPassword_Login()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                EmailTemplates.UserAccountRecover,
                "alice@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = TestServerBuilderExtensions
                                .CreateServer(emailServiceMock);

            HttpClient client = server.CreateClient();

            // 1. Call the recovery page and Fill out the form and submit
            HttpResponseMessage response = await client
                                           .RecoveryGetAndPostFormAsync("alice@localhost");

            Assert.NotNull(confirmUrl);
            Assert.NotNull(cancelUrl);

            // Call the confirmation link and fill out the form
            HttpResponseMessage confirmResponse = await client
                                                  .RecoveryConfirmGetAndPostFormAsync(
                confirmUrl,
                "new-password"
                );

            HttpResponseMessage consentPostResponse = await
                                                      client.ConstentPostFormAsync(false, confirmResponse);

            // Calling confirm url again shouldnt be possible
            await client.RecoveryConfirmGetInvalidAsync(cancelUrl);

            // Calling cancel url shouldnt be possible after successfull
            // confirmation
            await client.RecoveryCancelGetInvalidAsync(cancelUrl);

            HttpResponseMessage loginResponse = await client
                                                .LoginGetAndPostFormAsync("alice@localhost", "new-password");

            loginResponse.ShouldBeRedirectedToAuthorizeEndpoint();
        }
コード例 #6
0
        public async Task Try_Recover(
            string email,
            string[] errorMsgs)
        {
            TestServer server = TestServerBuilderExtensions.CreateServer();
            HttpClient client = server.CreateClient();

            HttpResponseMessage response = await client
                                           .RecoveryGetAndPostFormAsync(email);

            IHtmlDocument doc = await response.Content
                                .ReadAsHtmlDocumentAsync();

            doc.ShouldContainErrors(errorMsgs);
        }
コード例 #7
0
 private TestServer CreateServer(
     Mock <IEmailService> emailServiceMock = null)
 {
     return(TestServerBuilderExtensions.CreateServer(emailServiceMock));
 }