public void DefaultFactoryIsListedInRegisteredFactories()
        {
            // Arrange
            var factory = new HashVirtualPathFactory();

            // Act
            var factoryManager = new VirtualPathFactoryManager(factory);

            // Assert
            Assert.Equal(factory, factoryManager.RegisteredFactories.Single());
        }
Esempio n. 2
0
        public static string RenderWebPageWithSubPage(Action <WebPage> pageExecuteAction, Action <WebPage> subpageExecuteAction,
                                                      string pagePath = "~/index.cshtml", string subpagePath = "~/subpage.cshtml")
        {
            var page               = CreatePage(pageExecuteAction);
            var subPage            = CreatePage(subpageExecuteAction, subpagePath);
            var virtualPathFactory = new HashVirtualPathFactory(page, subPage);

            subPage.VirtualPathFactory = virtualPathFactory;
            page.VirtualPathFactory    = virtualPathFactory;
            return(RenderWebPage(page));
        }
        public void DefaultFactoryIsListedInRegisteredFactories()
        {
            // Arrange
            var factory = new HashVirtualPathFactory();

            // Act
            var factoryManager = new VirtualPathFactoryManager(factory);

            // Assert
            Assert.Equal(factory, factoryManager.RegisteredFactories.Single());
        }
        public void GenericCreateInstanceReturnsNullIfNoFactoryCanCreateVirtualPath()
        {
            // Arrange
            var factory1 = new HashVirtualPathFactory(Utils.CreatePage(_ => { }, "~/index.cshtml"));
            var factory2 = new HashVirtualPathFactory(Utils.CreatePage(null, "~/_admin/index.cshtml"));

            // Act
            var factoryManager = new VirtualPathFactoryManager(factory2);
            factoryManager.RegisterVirtualPathFactoryInternal(factory1);
            var page = factoryManager.CreateInstance<WebPageBase>("~/does-not-exist.cshtml");

            // Assert
            Assert.Null(page);
        }
        public void NormalizeLayoutPageAcceptsRelativePathsToLayoutPage()
        {
            // Arrange
            var page = Utils.CreatePage(null, "~/dir/default.cshtml");
            var layoutPage = Utils.CreatePage(null, "~/layouts/sitelayout.cshtml");
            var objectFactory = new HashVirtualPathFactory(page, layoutPage);
            page.VirtualPathFactory = objectFactory;

            // Act
            var path = page.NormalizeLayoutPagePath(@"../layouts/sitelayout.cshtml");

            // Assert
            Assert.Equal(path, layoutPage.VirtualPath);
        }
Esempio n. 6
0
        public void NormalizeLayoutPageAcceptsRelativePathsToLayoutPage()
        {
            // Arrange
            var page          = Utils.CreatePage(null, "~/dir/default.cshtml");
            var layoutPage    = Utils.CreatePage(null, "~/layouts/sitelayout.cshtml");
            var objectFactory = new HashVirtualPathFactory(page, layoutPage);

            page.VirtualPathFactory = objectFactory;

            // Act
            var path = page.NormalizeLayoutPagePath(@"../layouts/sitelayout.cshtml");

            // Assert
            Assert.Equal(path, layoutPage.VirtualPath);
        }
Esempio n. 7
0
        public void GenericCreateInstanceReturnsNullIfNoFactoryCanCreateVirtualPath()
        {
            // Arrange
            var factory1 = new HashVirtualPathFactory(Utils.CreatePage(_ => { }, "~/index.cshtml"));
            var factory2 = new HashVirtualPathFactory(Utils.CreatePage(null, "~/_admin/index.cshtml"));

            // Act
            var factoryManager = new VirtualPathFactoryManager(factory2);

            factoryManager.RegisterVirtualPathFactoryInternal(factory1);
            var page = factoryManager.CreateInstance <WebPageBase>("~/does-not-exist.cshtml");

            // Assert
            Assert.Null(page);
        }
Esempio n. 8
0
        public void CreatePageFromVirtualPathAssignsVirtualPathFactory()
        {
            // Arrange
            var path    = "~/index.cshtml";
            var page    = Utils.CreatePage(null, path);
            var factory = new HashVirtualPathFactory(page);

            // Act
            var result = WebPage.CreateInstanceFromVirtualPath(path, factory);

            // Assert
            Assert.Equal(page, result);
            Assert.Equal(page.VirtualPathFactory, factory);
            Assert.Equal(page.VirtualPath, path);
        }
        public void CreatePageFromVirtualPathAssignsVirtualPathFactory()
        {
            // Arrange
            var path = "~/index.cshtml";
            var page = Utils.CreatePage(null, path);
            var factory = new HashVirtualPathFactory(page);

            // Act
            var result = WebPage.CreateInstanceFromVirtualPath(path, factory);

            // Assert
            Assert.Equal(page, result);
            Assert.Equal(page.VirtualPathFactory, factory);
            Assert.Equal(page.VirtualPath, path);
        }
        public void GenericCreateInstanceLoopsOverAllRegisteredFactories()
        {
            // Arrange
            var virtualPath = "~/index.cshtml";
            var mockPage = Utils.CreatePage(_ => { }, virtualPath);
            var factory1 = new HashVirtualPathFactory(mockPage);
            var factory2 = new HashVirtualPathFactory(Utils.CreatePage(null, "~/_admin/index.cshtml"));

            // Act
            var factoryManager = new VirtualPathFactoryManager(factory2);
            factoryManager.RegisterVirtualPathFactoryInternal(factory1);
            var page = factoryManager.CreateInstance<WebPageBase>(virtualPath);

            // Assert
            Assert.Equal(mockPage, page);
        }
Esempio n. 11
0
        public void GenericCreateInstanceLoopsOverAllRegisteredFactories()
        {
            // Arrange
            var virtualPath = "~/index.cshtml";
            var mockPage    = Utils.CreatePage(_ => { }, virtualPath);
            var factory1    = new HashVirtualPathFactory(mockPage);
            var factory2    = new HashVirtualPathFactory(Utils.CreatePage(null, "~/_admin/index.cshtml"));

            // Act
            var factoryManager = new VirtualPathFactoryManager(factory2);

            factoryManager.RegisterVirtualPathFactoryInternal(factory1);
            var page = factoryManager.CreateInstance <WebPageBase>(virtualPath);

            // Assert
            Assert.Equal(mockPage, page);
        }
Esempio n. 12
0
        /// <summary>
        /// Assigns a common object factory to the pages.
        /// </summary>
        internal static IVirtualPathFactory AssignObjectFactoriesAndDisplayModeProvider(params WebPageExecutingBase[] pages)
        {
            var objectFactory       = new HashVirtualPathFactory(pages);
            var displayModeProvider = new DisplayModeProvider();

            foreach (var item in pages)
            {
                item.VirtualPathFactory = objectFactory;
                var webPageRenderingBase = item as WebPageRenderingBase;
                if (webPageRenderingBase != null)
                {
                    webPageRenderingBase.DisplayModeProvider = displayModeProvider;
                }
            }

            return(objectFactory);
        }
        public void RegisterFactoryEnsuresDefaultFactoryRemainsTheLast()
        {
            // Arrange
            var defaultFactory = new HashVirtualPathFactory();
            var factory1 = new HashVirtualPathFactory();
            var factory2 = new HashVirtualPathFactory();
            var factory3 = new HashVirtualPathFactory();

            // Act
            var factoryManager = new VirtualPathFactoryManager(defaultFactory);
            factoryManager.RegisterVirtualPathFactoryInternal(factory1);
            factoryManager.RegisterVirtualPathFactoryInternal(factory2);
            factoryManager.RegisterVirtualPathFactoryInternal(factory3);

            // Assert
            Assert.Equal(factory1, factoryManager.RegisteredFactories.ElementAt(0));
            Assert.Equal(factory2, factoryManager.RegisteredFactories.ElementAt(1));
            Assert.Equal(factory3, factoryManager.RegisteredFactories.ElementAt(2));
            Assert.Equal(defaultFactory, factoryManager.RegisteredFactories.Last());
        }
        public void RegisterFactoryEnsuresDefaultFactoryRemainsTheLast()
        {
            // Arrange
            var defaultFactory = new HashVirtualPathFactory();
            var factory1       = new HashVirtualPathFactory();
            var factory2       = new HashVirtualPathFactory();
            var factory3       = new HashVirtualPathFactory();

            // Act
            var factoryManager = new VirtualPathFactoryManager(defaultFactory);

            factoryManager.RegisterVirtualPathFactoryInternal(factory1);
            factoryManager.RegisterVirtualPathFactoryInternal(factory2);
            factoryManager.RegisterVirtualPathFactoryInternal(factory3);

            // Assert
            Assert.Equal(factory1, factoryManager.RegisteredFactories.ElementAt(0));
            Assert.Equal(factory2, factoryManager.RegisteredFactories.ElementAt(1));
            Assert.Equal(factory3, factoryManager.RegisteredFactories.ElementAt(2));
            Assert.Equal(defaultFactory, factoryManager.RegisteredFactories.Last());
        }
Esempio n. 15
0
 public static string RenderWebPageWithSubPage(Action<WebPage> pageExecuteAction, Action<WebPage> subpageExecuteAction,
                                               string pagePath = "~/index.cshtml", string subpagePath = "~/subpage.cshtml")
 {
     var page = CreatePage(pageExecuteAction);
     var subPage = CreatePage(subpageExecuteAction, subpagePath);
     var virtualPathFactory = new HashVirtualPathFactory(page, subPage);
     subPage.VirtualPathFactory = virtualPathFactory;
     page.VirtualPathFactory = virtualPathFactory;
     return RenderWebPage(page);
 }
Esempio n. 16
0
        /// <summary>
        /// Assigns a common object factory to the pages.
        /// </summary>
        internal static IVirtualPathFactory AssignObjectFactoriesAndDisplayModeProvider(params WebPageExecutingBase[] pages)
        {
            var objectFactory = new HashVirtualPathFactory(pages);
            var displayModeProvider = new DisplayModeProvider();
            foreach (var item in pages)
            {
                item.VirtualPathFactory = objectFactory;
                var webPageRenderingBase = item as WebPageRenderingBase;
                if (webPageRenderingBase != null)
                {
                    webPageRenderingBase.DisplayModeProvider = displayModeProvider;
                }
            }

            return objectFactory;
        }