Example #1
0
        public async Task ItShouldReturnTheChallengeForm()
        {
            var downloadedFormHtml = "<html><form action='' method='post' /></html>";
            var mappedFormHtml     = "<html><form action='/api/challenge/id'  method='post' /></html>";


            MockSiteConnector.Setup(c => c.Download(It.IsAny <Uri>()))
            .ReturnsAsync(downloadedFormHtml);

            MockFormMapper.Setup(x => x.UpdateForm(
                                     It.IsAny <SupportServiceResourceKey>(),
                                     It.IsAny <SupportServiceResourceKey>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>()
                                     ))
            .Returns(mappedFormHtml);

            var actual = await Unit.GetChallengeForm(
                SupportServiceResourceKey.EmployerAccountFinance,
                SupportServiceResourceKey.EmployerAccountFinanceChallenge,
                "id",
                "http://tempuri.org/challenge/form");

            Assert.IsFalse(string.IsNullOrWhiteSpace(actual));
            Assert.IsTrue(actual.Contains("<html"));
            Assert.IsTrue(actual.Contains("<form"));
        }
        public async Task ItShouldReceiveAFormResponseOnFail()
        {
            var mappedFormHtml = "<form action='/api/challenge/id'  method='post' />";

            MockFormMapper.Setup(x => x.UpdateForm(
                                     It.IsAny <SupportServiceResourceKey>(),
                                     It.IsAny <SupportServiceResourceKey>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>()
                                     ))
            .Returns(mappedFormHtml);


            MockSiteConnector
            .Setup(x => x.Upload <string>(It.IsAny <Uri>(), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(mappedFormHtml);

            MockSiteConnector.SetupGet(x => x.LastCode).Returns(HttpStatusCode.OK);

            var result = await Unit.SubmitChallenge(_id, _submittedFormData);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.HasRedirect);
            Assert.IsNull(result.RedirectUrl);
            Assert.AreEqual(mappedFormHtml, result.Page);
        }
Example #3
0
        public void ItShouldNotThrowAnExceptionIfTheSiteManifestNull()
        {
            MockSiteConnector.Setup(x => x.Download <SiteManifest>(TestSiteUri)).ReturnsAsync(null as SiteManifest);

            Assert.DoesNotThrow(() =>
            {
                var response = Unit.GetChallengeForm(SupportServiceResourceKey.EmployerAccountFinance, SupportServiceResourceKey.EmployerAccountFinanceChallenge, "id",
                                                     "http://tempuri.org/callenge/form");
            });
        }
        public async Task ItShouldReturnTheHtmlPage()
        {
            var html = "<html>Some page</html>";

            MockSiteConnector.Setup(x => x.Download(It.IsAny <Uri>()))
            .ReturnsAsync(html);
            var result = await Unit.GetResourcePage(SupportServiceResourceKey.EmployerAccountFinance, "id", "childItemId");

            Assert.IsFalse(string.IsNullOrWhiteSpace(result.Resource));
        }
        public async Task ItShouldReturnAPageIfTheResourceDoesExistAndCanBeAccessed()
        {
            var html = "<html>This is a page</html>";

            MockSiteConnector.Setup(x => x.Download(It.IsAny <Uri> ()))
            .ReturnsAsync(html);

            var result = await Unit.GenerateHeader(SupportServiceResourceKey.EmployerAccountFinance, "id");

            Assert.IsNotNull(result);
            Assert.IsFalse($"{result}".Contains("There was a problem downloading this asset"));
            Assert.AreEqual(html, result.Resource);
        }
        public void ItShouldThrownAnExceptionIfTheSubmissionErrors()
        {
            var httpException = new HttpException();

            MockSiteConnector
            .Setup(x => x.Upload <string>(It.IsAny <Uri>(), _postedFormData))
            .ThrowsAsync(httpException);

            MockSiteConnector.SetupGet(x => x.LastCode).Returns(HttpStatusCode.InternalServerError);
            MockSiteConnector.SetupGet(x => x.LastException).Returns(httpException);


            Assert.ThrowsAsync <HttpException>(() => Unit.SubmitChallenge(_id, _submittedFormData));
        }
        public async Task ItShouldReceiveJustARedirectOnSuccess()
        {
            var challengeResult = new ChallengeValidationResult
            {
                IsValidResponse = true
            };

            MockSiteConnector
            .Setup(x => x.Upload <string>(It.IsAny <Uri>(), It.IsAny <IDictionary <string, string> >()))
            .Returns(Task.FromResult(JsonConvert.SerializeObject(challengeResult)));

            var result = await Unit.SubmitChallenge(_id, _submittedFormData);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.HasRedirect);
            Assert.AreEqual(_redirectUrl, result.RedirectUrl);
            Assert.IsNull(result.Page);
        }