Пример #1
0
        public void GetVirtualPath_IPageTemplate_ReturnsNull()
        {
            //Arrange
            LayoutResolver resolver = new LayoutResolver();
            DummyFrameworkSpecificPageTemplate dummyPageTemplate = new DummyFrameworkSpecificPageTemplate(PageTemplateFramework.Mvc);

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(),
                                                                                    new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();

                VirtualPathManager.AddVirtualFileResolver <DummyVirtualFileResolver>(LayoutResolverTests.testVp, "DummyVirtualFileResolver");

                //Act
                try
                {
                    var resolvedVirtualPath = resolver.GetVirtualPath(dummyPageTemplate);

                    //Assert
                    Assert.IsNull(resolvedVirtualPath, "Resolved VirtualPath should be null.");
                }
                finally
                {
                    VirtualPathManager.RemoveVirtualFileResolver(LayoutResolverTests.testVp);
                }
            }
        }
Пример #2
0
        public void GetVirtualPath_InvalidCharacters_ReturnsCleanVirtualPath()
        {
            //Arrange
            string         dirtyTitle       = "Some<>*Test:?Title";
            string         cleanVirtualPath = "~/SfLayouts/Some_Test_Title.master";
            string         resolvedVirtualPath;
            LayoutResolver resolver = new LayoutResolver();

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(),
                                                                                    new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();
                VirtualPathManager.AddVirtualFileResolver <DummyVirtualFileResolver>(LayoutResolverTests.testVp, "DummyVirtualFileResolver");

                var dummyPageTemplate = new DummyPageTemplateWithTitle(PageTemplateFramework.Mvc, dirtyTitle);

                //Act
                try
                {
                    resolvedVirtualPath = resolver.GetVirtualPath(dummyPageTemplate);

                    //Assert
                    Assert.AreEqual(cleanVirtualPath, resolvedVirtualPath, "GetVirtualPath method doesn't return correct string.");
                }
                finally
                {
                    VirtualPathManager.RemoveVirtualFileResolver(LayoutResolverTests.testVp);
                }
            }
        }
        public void GetCacheDependency_ExistingResource_ReturnsDependencyWithId()
        {
            const string virtualPath    = "Test/MyTemplate.cshtml";
            Guid         presentationId = new Guid("4B9F6715-014E-4B1E-887F-428AF942EAC8");

            var resolver = new DummyDatabaseResourceResolver();

            resolver.GetControlPresentationResult[virtualPath] = new ControlPresentation(null, presentationId);

            CacheDependency result = null;

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(),
                                                                                    new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <SystemConfig>();

                result = resolver.GetCacheDependency(new PathDefinition(), virtualPath, null, DateTime.UtcNow);
            }
            Assert.IsInstanceOfType(result, typeof(ControlPresentationCacheDependency), "Returned cache dependency was not of the expected type.");

            var presentationDependency = (ControlPresentationCacheDependency)result;
            var itemId = presentationDependency.GetType().GetField("itemId", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(presentationDependency) as string;

            Assert.AreEqual(presentationId.ToString().ToLower(), itemId.ToLower(),
                            "GetCacheDependency did not return dependency on the expected object.");
        }
Пример #4
0
        public void PopulateScriptReferences_ViewsCollection_ConstructScriptReferencesCollection()
        {
            // TODO: Reduce class coupling
            // Arrange
            string widgetName = "Dummy";
            var    views      = new List <string>();

            views.Add("DesignerView.someViewName");
            var designerViewConfigs = this.CreateDummyDesignerViewConfigModel();

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(), new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();
                Config.RegisterSection <ResourcesConfig>();

                using (var factoryReg = new ControllerFactoryRegion <DummyControllerFactory>())
                {
                    factoryReg.Factory.ControllerRegistry["Dummy"]    = typeof(DummyController);
                    factoryReg.Factory.ControllerRegistry["Designer"] = typeof(DesignerController);

                    var fileResolverPrefix = "~/Frontend-Assembly";
                    VirtualPathManager.AddVirtualFileResolver <DummyVirtualFileResolver>(fileResolverPrefix + "*", "DummyVirtualFileResolver");

                    var dummyModel = new DummyDesignerModel(views, new List <string>(), widgetName, Guid.Empty, "someViewName");

                    try
                    {
                        // Act
                        dummyModel.PopulateScriptReferencesPublic(widgetName, designerViewConfigs);
                    }
                    finally
                    {
                        VirtualPathManager.RemoveVirtualFileResolver(fileResolverPrefix);
                        VirtualPathManager.Reset();
                    }

                    // Assert
                    Assert.AreEqual(4, dummyModel.ScriptReferences.Count(), "The script count is not as expected.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains("Mvc/Scripts/Dummy/designerview-someviewname.js"), "ScriptReferences doesn't contain scripts for the view.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script1), "ScriptReferences doesn't contain expected scripts.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script2), "ScriptReferences doesn't contain expected scripts.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script3), "ScriptReferences doesn't contain expected scripts.");
                }
            }
        }
        /// <summary>
        /// Gets the cache dependency result.
        /// </summary>
        /// <param name="resolver">The resolver.</param>
        /// <param name="virtualPath">The virtual path.</param>
        /// <returns></returns>
        private ControlPresentationCacheDependency GetCacheDependencyResult(DummyDatabaseResourceResolver resolver, string virtualPath)
        {
            CacheDependency result = null;

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(), new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <SystemConfig>();

                result = resolver.GetCacheDependency(new PathDefinition(), virtualPath, null, DateTime.UtcNow);
            }

            Assert.IsInstanceOfType(result, typeof(ControlPresentationCacheDependency), "Returned cache dependency was not of the expected type.");

            var presentationDependency = (ControlPresentationCacheDependency)result;

            return(presentationDependency);
        }
        public void GetCacheDependency_NonExistingResource_ReturnsDependencyWithoutId()
        {
            const string virtualPath = "Test/MyTemplate.cshtml";

            var             resolver = new DummyDatabaseResourceResolver();
            CacheDependency result   = null;

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(),
                                                                                    new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <SystemConfig>();

                result = resolver.GetCacheDependency(new PathDefinition(), virtualPath, null, DateTime.UtcNow);
            }
            Assert.IsInstanceOfType(result, typeof(ControlPresentationCacheDependency), "Returned cache dependency was not of the expected type.");

            var presentationDependency = (ControlPresentationCacheDependency)result;
            var itemId = presentationDependency.GetType().GetField("itemId", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(presentationDependency) as string;

            Assert.IsNull(itemId, "The returned CacheDependency has an unexpected key.");
        }