예제 #1
0
        /// <summary>
        ///     Uses the browser to execute a GET request to the specified location and validates against the specified HTTP status
        ///     code.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of page to return.
        /// </typeparam>
        /// <param name="browser">
        ///     The browser.
        /// </param>
        /// <param name="location">
        ///     The location to request.
        /// </param>
        /// <param name="expectedStatusCode">
        ///     The expected HTTP status code.
        /// </param>
        /// <returns>
        ///     A <typeparamref name="T" /> value.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="browser" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="location" /> parameter is <c>null</c>.
        /// </exception>
        public static T GoTo <T>(this IBrowser browser, Uri location, HttpStatusCode expectedStatusCode)
            where T : IPage, new()
        {
            var pageFactory = new DefaultPageFactory();

            return(browser.GoTo <T>(location, expectedStatusCode, pageFactory));
        }
        public void CreateInitializesNewPageInstanceTest()
        {
            var data = Guid.NewGuid().ToString();
            var response = new HttpResponseMessage
            {
                Content = new StringContent(data)
            };
            var outcomes = new List<HttpOutcome>
            {
                new HttpOutcome(
                    new Uri("http://www.google.com"),
                    HttpMethod.Get,
                    HttpStatusCode.OK,
                    Guid.NewGuid().ToString(),
                    TimeSpan.FromMilliseconds(2))
            };
            var result = new HttpResult(new ReadOnlyCollection<HttpOutcome>(outcomes));

            var browser = Substitute.For<IBrowser>();

            var target = new DefaultPageFactory();

            var actual = target.Create<TextPageWrapper>(browser, response, result);

            actual.Should().NotBeNull();
            actual.Browser.Should().Be(browser);
            actual.Result.Should().Be(result);
            actual.StatusCode.Should().Be(response.StatusCode);
            actual.StatusDescription.Should().Be(response.ReasonPhrase);
            actual.Content.Should().Be(data);
        }
예제 #3
0
        public void CreatePageWithInjectedService()
        {
            // Arrange
            var pageFactory = new DefaultPageFactory();
            var pageContext = new PageContext()
            {
                HttpContext    = BuildHttpContext(),
                PageDescriptor = new PageDescriptor
                {
                    PageType     = typeof(ServicePage),
                    RelativePath = "ServicePage"
                }
            };

            // Act
            var page = (ServicePage)pageFactory.CreatePage(pageContext);

            // Assert
            Assert.NotNull(page.HostingEnvironment);

            HttpContext BuildHttpContext()
            {
                var context  = new DefaultHttpContext();
                var services = new ServiceCollection();

                services.AddSingleton <IHostingEnvironment, HostingEnvironment>();
                context.RequestServices = new DefaultServiceProviderFactory()
                                          .CreateServiceProvider(services);

                return(context);
            }
        }
        public void CreateInitializesNewPageInstanceTest()
        {
            var data     = Guid.NewGuid().ToString();
            var response = new HttpResponseMessage
            {
                Content = new StringContent(data)
            };
            var outcomes = new List <HttpOutcome>
            {
                new HttpOutcome(
                    new Uri("http://www.google.com"),
                    HttpMethod.Get,
                    HttpStatusCode.OK,
                    Guid.NewGuid().ToString(),
                    TimeSpan.FromMilliseconds(2))
            };
            var result = new HttpResult(new ReadOnlyCollection <HttpOutcome>(outcomes));

            var browser = Substitute.For <IBrowser>();

            var target = new DefaultPageFactory();

            var actual = target.Create <TextPageWrapper>(browser, response, result);

            actual.Should().NotBeNull();
            actual.Browser.Should().Be(browser);
            actual.Result.Should().Be(result);
            actual.StatusCode.Should().Be(response.StatusCode);
            actual.StatusDescription.Should().Be(response.ReasonPhrase);
            actual.Content.Should().Be(data);
        }
예제 #5
0
        /// <summary>
        ///     Uses the browser to execute a GET request to the specified location and validates against the specified HTTP status
        ///     code.
        /// </summary>
        /// <param name="browser">
        ///     The browser.
        /// </param>
        /// <param name="location">
        ///     The location to request.
        /// </param>
        /// <param name="expectedStatusCode">
        ///     The expected HTTP status code.
        /// </param>
        /// <returns>
        ///     An <see cref="IPage" /> value.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="browser" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="location" /> parameter is <c>null</c>.
        /// </exception>
        public static dynamic GoTo(this IBrowser browser, Uri location, HttpStatusCode expectedStatusCode)
        {
            var pageFactory = new DefaultPageFactory();

            var dynamicPage = browser.GoTo <DynamicResolverPage>(location, expectedStatusCode, pageFactory);

            return(dynamicPage.ResolvedPage);
        }
예제 #6
0
        /// <summary>
        ///     Uses the browser to execute a POST request with the specified parameters to the specified location and validates
        ///     against the specified HTTP status code.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of page to return.
        /// </typeparam>
        /// <param name="browser">
        ///     The browser.
        /// </param>
        /// <param name="parameters">
        ///     The POST parameters.
        /// </param>
        /// <param name="location">
        ///     The location to post to.
        /// </param>
        /// <param name="expectedStatusCode">
        ///     The expected HTTP status code.
        /// </param>
        /// <returns>
        ///     A <typeparamref name="T" /> value.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="browser" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="parameters" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="location" /> parameter is <c>null</c>.
        /// </exception>
        public static T PostTo <T>(
            this IBrowser browser,
            IEnumerable <PostEntry> parameters,
            Uri location,
            HttpStatusCode expectedStatusCode) where T : IPage, new()
        {
            var pageFactory = new DefaultPageFactory();

            return(browser.PostTo <T>(parameters, location, expectedStatusCode, pageFactory));
        }
예제 #7
0
        private static Tuple <IEngineCore, IPageLookup> CreateDefaultDependencies(
            ITemplateManager manager,
            IEngineConfiguration configuration)
        {
            IEngineCore core = new EngineCore(manager, configuration);

            IPageFactoryProvider pageFactory = new DefaultPageFactory(core.KeyCompile);
            IPageLookup          lookup      = new DefaultPageLookup(pageFactory);

            return(new Tuple <IEngineCore, IPageLookup>(core, lookup));
        }
예제 #8
0
        /// <summary>
        ///     Uses the browser to execute a POST request with the specified parameters to the specified location and validates
        ///     against the specified HTTP status code.
        /// </summary>
        /// <param name="browser">
        ///     The browser.
        /// </param>
        /// <param name="parameters">
        ///     The POST parameters.
        /// </param>
        /// <param name="location">
        ///     The location to request.
        /// </param>
        /// <param name="expectedStatusCode">
        ///     The expected HTTP status code.
        /// </param>
        /// <returns>
        ///     An <see cref="IPage" /> value.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="browser" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="parameters" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="location" /> parameter is <c>null</c>.
        /// </exception>
        public static dynamic PostTo(
            this IBrowser browser,
            IEnumerable <PostEntry> parameters,
            Uri location,
            HttpStatusCode expectedStatusCode)
        {
            var pageFactory = new DefaultPageFactory();

            var dynamicPage = browser.PostTo <DynamicResolverPage>(parameters, location, expectedStatusCode, pageFactory);

            return(dynamicPage.ResolvedPage);
        }
예제 #9
0
        public void CreatePageWithEmptyContextReturnNull()
        {
            // Arrange
            var pageFactory = new DefaultPageFactory();
            var pageContext = new PageContext();

            // Act
            var page = pageFactory.CreatePage(pageContext);

            // Assert
            Assert.Null(page);
        }
예제 #10
0
        public RazorViewMailService(
            GlobalSettings globalSettings,
            IMailDeliveryService mailDeliveryService)
        {
            _globalSettings      = globalSettings;
            _mailDeliveryService = mailDeliveryService;

            var manager     = new CustomEmbeddedResourceTemplateManager("Bit.Core.MailTemplates");
            var core        = new EngineCore(manager, EngineConfiguration.Default);
            var pageFactory = new DefaultPageFactory(core.KeyCompile);
            var lookup      = new DefaultPageLookup(pageFactory);

            _engine = new RazorLightEngine(core, lookup);
        }
예제 #11
0
        public void CreatePage()
        {
            // Arrange
            var pageFactory = new DefaultPageFactory();
            var pageContext = new PageContext
            {
                Page           = new TestPage(),
                PageDescriptor = new PageDescriptor
                {
                    PageType     = typeof(TestPage),
                    RelativePath = "Test"
                }
            };

            // Act
            var page = pageFactory.CreatePage(pageContext);

            // Assert
            Assert.NotNull(page);
        }