Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public void CreatePageWithEmptyContextReturnNull()
        {
            // Arrange
            var pageFactory = new DefaultPageFactory();
            var pageContext = new PageContext();

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

            // Assert
            Assert.Null(page);
        }
Esempio n. 3
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);
        }