コード例 #1
0
        public void TimeSpanProperty() {
            // Arrange
            TimeSpan timeSpan = new TimeSpan(0, 20, 0);
            DefaultViewLocationCache viewCache = new DefaultViewLocationCache(timeSpan);

            // Assert
            Assert.AreEqual(timeSpan.Ticks, viewCache.TimeSpan.Ticks);
        }
コード例 #2
0
        public void ConstructorAssignsDefaultTimeSpan() {
            // Arrange
            DefaultViewLocationCache viewLocationCache = new DefaultViewLocationCache();
            TimeSpan timeSpan = new TimeSpan(0, 15, 0);

            // Assert
            Assert.AreEqual(timeSpan.Ticks, viewLocationCache.TimeSpan.Ticks);
        }
        public void TimeSpanProperty()
        {
            // Arrange
            TimeSpan timeSpan = new TimeSpan(0, 20, 0);
            DefaultViewLocationCache viewCache = new DefaultViewLocationCache(timeSpan);

            // Assert
            Assert.Equal(timeSpan.Ticks, viewCache.TimeSpan.Ticks);
        }
コード例 #4
0
        public void ConstructorAssignsDefaultTimeSpan()
        {
            // Arrange
            DefaultViewLocationCache viewLocationCache = new DefaultViewLocationCache();
            TimeSpan timeSpan = new TimeSpan(0, 15, 0);

            // Assert
            Assert.Equal(timeSpan.Ticks, viewLocationCache.TimeSpan.Ticks);
        }
コード例 #5
0
        /// <summary>
        /// Create the core instance of the ViewEngine
        /// </summary>
        /// <param name="cacheProvider">The cache provider holding reusable items</param>
        public HandlebarsViewEngine(ICacheProvider cacheProvider)
        {
            ViewLocationFormats        = HandlebarsViewEngineConfiguration.ViewLocationFormats.ToArray();
            PartialViewLocationFormats = ViewLocationFormats;
            ViewLocationCache          = new DefaultViewLocationCache(TimeSpan.FromDays(1));

            _handlebars   = Handlebars.Create(Handlebars.Configuration);
            CacheProvider = cacheProvider ?? throw new ArgumentNullException(nameof(cacheProvider));
        }
コード例 #6
0
        public void FindView_DoesNotInvokeExpandViewLocations_IfCacheEntryMatchesButViewIsNotFound()
        {
            // Arrange
            var pageFactory       = Mock.Of <IRazorPageFactory>();
            var viewFactory       = Mock.Of <IRazorViewFactory>();
            var cache             = new DefaultViewLocationCache();
            var expander          = new Mock <IViewLocationExpander>();
            var expandedLocations = new[]
            {
                "viewlocation1",
                "viewlocation2",
                "viewlocation3",
            };

            expander
            .Setup(v => v.PopulateValues(It.IsAny <ViewLocationExpanderContext>()))
            .Callback((ViewLocationExpanderContext expanderContext) =>
            {
                expanderContext.Values["somekey"] = "somevalue";
            })
            .Verifiable();
            expander
            .Setup(v => v.ExpandViewLocations(
                       It.IsAny <ViewLocationExpanderContext>(), It.IsAny <IEnumerable <string> >()))
            .Returns((ViewLocationExpanderContext c, IEnumerable <string> viewLocations) => expandedLocations)
            .Verifiable();


            var viewEngine = CreateViewEngine(
                pageFactory,
                viewFactory,
                expanders: new[] { expander.Object },
                cache: cache);
            var context = GetActionContext(_controllerTestContext);

            // Act - 1
            var result = viewEngine.FindView(context, "myview");

            // Assert - 1
            Assert.False(result.Success);
            Assert.Equal(expandedLocations, result.SearchedLocations);
            expander.Verify();

            // Act - 2
            result = viewEngine.FindView(context, "myview");

            // Assert - 2
            Assert.False(result.Success);
            Assert.Equal(expandedLocations, result.SearchedLocations);
            expander.Verify(
                v => v.PopulateValues(It.IsAny <ViewLocationExpanderContext>()),
                Times.Exactly(2));
            expander.Verify(
                v => v.ExpandViewLocations(It.IsAny <ViewLocationExpanderContext>(), It.IsAny <IEnumerable <string> >()),
                Times.Once());
        }
コード例 #7
0
        public void InsertViewLocationThrowsWithNullHttpContext()
        {
            // Arrange
            DefaultViewLocationCache viewLocationCache = new DefaultViewLocationCache();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { viewLocationCache.InsertViewLocation(null /* httpContext */, "foo", "fooPath"); },
                "httpContext");
        }
コード例 #8
0
        public void InsertViewLocationThrowsWithNullHttpContext()
        {
            // Arrange
            DefaultViewLocationCache viewLocationCache = new DefaultViewLocationCache();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { viewLocationCache.InsertViewLocation(null /* httpContext */, "foo", "fooPath"); },
                "httpContext");
        }
コード例 #9
0
 protected ThemedVirtualPathProviderViewEngine()
 {
     if (HttpContext.Current == null || HttpContext.Current.IsDebuggingEnabled)
     {
         ViewLocationCache = DefaultViewLocationCache.Null;
     }
     else
     {
         ViewLocationCache = new DefaultViewLocationCache();
     }
 }
コード例 #10
0
        public void GetViewLocationThrowsWithNullHttpContext() {
            // Arrange
            DefaultViewLocationCache viewLocationCache = new DefaultViewLocationCache();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                    string viewLocation = viewLocationCache.GetViewLocation(null /* httpContext */, "foo");
                },
                "httpContext");
        }
コード例 #11
0
        public MercedesViewEngine()
        {
            ViewLocationCache       = new DefaultViewLocationCache(TimeSpan.FromHours(1));
            AreaViewLocationFormats = new[]
            {
                //default
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml",
            };

            AreaMasterLocationFormats = new[]
            {
                //default
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml",
            };

            AreaPartialViewLocationFormats = new[]
            {
                //default
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml"
            };
            ViewLocationFormats = new[]
            {
                //default
                "~/Views/{1}/{0}.cshtml",
                "~/Views/Shared/{0}.cshtml",

                //Admin
                "~/Administration/Views/{1}/{0}.cshtml",
                "~/Administration/Views/Shared/{0}.cshtml",
            };
            MasterLocationFormats = new[]
            {
                //default
                "~/Views/{1}/{0}.cshtml",
                "~/Views/Shared/{0}.cshtml"
            };

            PartialViewLocationFormats = new[]
            {
                //default
                "~/Views/{1}/{0}.cshtml",
                "~/Views/Shared/{0}.cshtml",

                //Admin
                "~/Administration/Views/{1}/{0}.cshtml",
                "~/Administration/Views/Shared/{0}.cshtml",
            };

            FileExtensions = new[] { "cshtml" };
        }
コード例 #12
0
        public void GetViewLocationThrowsWithNullHttpContext()
        {
            // Arrange
            DefaultViewLocationCache viewLocationCache = new DefaultViewLocationCache();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                string viewLocation = viewLocationCache.GetViewLocation(null /* httpContext */, "foo");
            },
                "httpContext");
        }
コード例 #13
0
 protected ThemeableVirtualPathProviderViewEngine()
 {
     //if (HttpContext.Current == null || HttpContext.Current.IsDebuggingEnabled)
     //{
     //    ViewLocationCache = DefaultViewLocationCache.Null;
     //}
     //else
     //{
     //    ViewLocationCache = new DefaultViewLocationCache();
     //}
     ViewLocationCache = new DefaultViewLocationCache(TimeSpan.FromHours(24));
 }
コード例 #14
0
        public TailspinViewEngine()
        {
            ViewLocationFormats = new[] {
                "~/{0}.aspx",
            };

            PartialViewLocationFormats = new[] {
                "~/Shared/{0}.ascx",
            };

            MasterLocationFormats = new[] {
                "~/{0}.master",
            };

            ViewLocationCache = new DefaultViewLocationCache();
        }
コード例 #15
0
ファイル: ThemedViewEngine.cs プロジェクト: a864610877/MEINUO
        public ThemedViewEngine(IViewPageActivator viewPageActivator)
        {
            _viewPageActivator = viewPageActivator;
            if (HttpContext.Current == null || HttpContext.Current.IsDebuggingEnabled)
            {
                ViewLocationCache = DefaultViewLocationCache.Null;
            }
            else
            {
                ViewLocationCache = new DefaultViewLocationCache();
            }

            // {1}appName , {2} theme
            AppNameViewLocationFormats = new[] {
                "~/Views/{1}/{2}/{0}.cshtml",
                "~/Views/{1}/{2}/Shared/{0}.cshtml",
                "~/Views/{1}/Default/{0}.cshtml",
                "~/Views/{1}/Default/Shared/{0}.cshtml",

                "~/Views/default/{0}.cshtml",
            };
            AppNameMasterLocationFormats = new[] {
                "~/Views/{1}/{2}/{0}.cshtml",
                "~/Views/{1}/{2}/Shared/{0}.cshtml",
                "~/Views/{1}/Default/{0}.cshtml",
                "~/Views/{1}/Default/Shared/{0}.cshtml",

                "~/Views/default/Shared/{0}.cshtml",
            };
            AppNamePartialViewLocationFormats = new[] {
                "~/Views/{1}/{2}/{0}.cshtml",
                "~/Views/{1}/{2}/Shared/{0}.cshtml",
                "~/Views/{1}/Default/{0}.cshtml",
                "~/Views/{1}/Default/Shared/{0}.cshtml",

                "~/Views/default/Shared/{0}.cshtml",
            };
        }
コード例 #16
0
        public FeaturesViewEngine()
        {
            ViewLocationCache = new DefaultViewLocationCache();

            var featureFolders = new[]
            {
                "~/Features/%1/{1}/{0}.cshtml",
                "~/Features/%1/{0}.cshtml"
            };

            featureFolders = featureFolders.Union(AdditionalPartialViewFormats).ToArray();

            ViewLocationFormats = ViewLocationFormats
                                  .Union(featureFolders)
                                  .ToArray();

            PartialViewLocationFormats = PartialViewLocationFormats
                                         .Union(featureFolders)
                                         .ToArray();

            MasterLocationFormats = MasterLocationFormats
                                    .Union(featureFolders)
                                    .ToArray();
        }
コード例 #17
0
        public void FindView_DoesNotInvokeExpandViewLocations_IfCacheEntryMatchesButViewIsNotFound()
        {
            // Arrange
            var pageFactory = Mock.Of<IRazorPageFactory>();
            var viewFactory = Mock.Of<IRazorViewFactory>();
            var cache = new DefaultViewLocationCache();
            var expander = new Mock<IViewLocationExpander>();
            var expandedLocations = new[]
            {
                "viewlocation1",
                "viewlocation2",
                "viewlocation3",
            };
            expander
                .Setup(v => v.PopulateValues(It.IsAny<ViewLocationExpanderContext>()))
                .Callback((ViewLocationExpanderContext expanderContext) =>
                {
                    expanderContext.Values["somekey"] = "somevalue";
                })
                .Verifiable();
            expander
                .Setup(v => v.ExpandViewLocations(
                    It.IsAny<ViewLocationExpanderContext>(), It.IsAny<IEnumerable<string>>()))
                .Returns((ViewLocationExpanderContext c, IEnumerable<string> viewLocations) => expandedLocations)
                .Verifiable();


            var viewEngine = CreateViewEngine(
                pageFactory,
                viewFactory,
                expanders: new[] { expander.Object },
                cache: cache);
            var context = GetActionContext(_controllerTestContext);

            // Act - 1
            var result = viewEngine.FindView(context, "myview");

            // Assert - 1
            Assert.False(result.Success);
            Assert.Equal(expandedLocations, result.SearchedLocations);
            expander.Verify();

            // Act - 2
            result = viewEngine.FindView(context, "myview");

            // Assert - 2
            Assert.False(result.Success);
            Assert.Equal(expandedLocations, result.SearchedLocations);
            expander.Verify(
                v => v.PopulateValues(It.IsAny<ViewLocationExpanderContext>()),
                Times.Exactly(2));
            expander.Verify(
                v => v.ExpandViewLocations(It.IsAny<ViewLocationExpanderContext>(), It.IsAny<IEnumerable<string>>()),
                Times.Once());
        }
コード例 #18
0
        public CustomRazorViewEngine()
        {
            var cache = new DefaultViewLocationCache(TimeSpan.FromDays(365));

            base.ViewLocationCache = cache;

            List <string> AreaViewLocationFormatsList = new List <string>();

            if (SF.UsePlugins())
            {
                AreaViewLocationFormatsList.Add("~/Plugins/{4}/Areas/{2}/Views/{1}/{0}.cshtml");
                AreaViewLocationFormatsList.Add("~/Plugins/{4}/Areas/{2}/Views/Shared/{0}.cshtml");
            }
            AreaViewLocationFormatsList.Add("~/Areas/{2}/Views/{1}/{0}.cshtml");
            AreaViewLocationFormatsList.Add("~/Areas/{2}/Views/Shared/{0}.cshtml");
            AreaViewLocationFormats = AreaViewLocationFormatsList.ToArray();

            List <string> AreaMasterLocationFormatsList = new List <string>();

            if (SF.UsePlugins())
            {
                AreaMasterLocationFormatsList.Add("~/Plugins/{4}/Areas/{2}/Views/{1}/{0}.cshtml");
                AreaMasterLocationFormatsList.Add("~/Plugins/{4}/Areas/{2}/Views/Shared/{0}.cshtml");
            }
            AreaMasterLocationFormatsList.Add("~/Areas/{2}/Views/{1}/{0}.cshtml");
            AreaMasterLocationFormatsList.Add("~/Areas/{2}/Views/Shared/{0}.cshtml");
            AreaMasterLocationFormats = AreaMasterLocationFormatsList.ToArray();

            List <string> AreaPartialViewLocationFormatsList = new List <string>();

            if (SF.UsePlugins())
            {
                AreaPartialViewLocationFormatsList.Add("~/Plugins/{4}/Areas/{2}/Views/{1}/{0}.cshtml");
                AreaPartialViewLocationFormatsList.Add("~/Plugins/{4}/Areas/{2}/Views/Shared/{0}.cshtml");
            }
            AreaPartialViewLocationFormatsList.Add("~/Areas/{2}/Views/{1}/{0}.cshtml");
            AreaPartialViewLocationFormatsList.Add("~/Areas/{2}/Views/Shared/{0}.cshtml");
            AreaPartialViewLocationFormats = AreaMasterLocationFormatsList.ToArray();

            List <string> ViewLocationFormatsList = new List <string>();

            if (SF.UseThemes())
            {
                ViewLocationFormatsList.Add("~/Themes/{2}/Views/{1}/{0}.cshtml");
                ViewLocationFormatsList.Add("~/Themes/{2}/Views/Shared/{0}.cshtml");
            }
            if (SF.UsePlugins())
            {
                ViewLocationFormatsList.Add("~/Plugins/{3}/Views/{1}/{0}.cshtml");
                ViewLocationFormatsList.Add("~/Plugins/{3}/Views/Shared/{0}.cshtml");
            }
            ViewLocationFormatsList.Add("~/Views/{1}/{0}.cshtml");
            ViewLocationFormatsList.Add("~/Views/Shared/{0}.cshtml");
            ViewLocationFormats = ViewLocationFormatsList.ToArray();

            List <string> MasterLocationFormatsList = new List <string>();

            if (SF.UseThemes())
            {
                MasterLocationFormatsList.Add("~/Themes/{2}/Views/{1}/{0}.cshtml");
                MasterLocationFormatsList.Add("~/Themes/{2}/Views/Shared/{0}.cshtml");
            }
            if (SF.UsePlugins())
            {
                MasterLocationFormatsList.Add("~/Plugins/{3}/Views/{1}/{0}.cshtml");
                MasterLocationFormatsList.Add("~/Plugins/{3}/Views/Shared/{0}.cshtml");
            }
            MasterLocationFormatsList.Add("~/Views/{1}/{0}.cshtml");
            MasterLocationFormatsList.Add("~/Views/Shared/{0}.cshtml");
            MasterLocationFormats = MasterLocationFormatsList.ToArray();

            List <string> PartialViewLocationFormatsList = new List <string>();

            if (SF.UseThemes())
            {
                PartialViewLocationFormatsList.Add("~/Themes/{2}/Views/{1}/{0}.cshtml");
                PartialViewLocationFormatsList.Add("~/Themes/{2}/Views/Shared/{0}.cshtml");
            }
            if (SF.UsePlugins())
            {
                PartialViewLocationFormatsList.Add("~/Plugins/{3}/Views/{1}/{0}.cshtml");
                PartialViewLocationFormatsList.Add("~/Plugins/{3}/Views/Shared/{0}.cshtml");
            }
            PartialViewLocationFormatsList.Add("~/Views/{1}/{0}.cshtml");
            PartialViewLocationFormatsList.Add("~/Views/Shared/{0}.cshtml");
            PartialViewLocationFormats = PartialViewLocationFormatsList.ToArray();

            ViewStartFileExtensions = new[] { "cshtml" };
        }
コード例 #19
0
		protected VirtualPathProviderViewEngine ()
		{
			if (HttpContext.Current == null || HttpContext.Current.IsDebuggingEnabled) {
				ViewLocationCache = DefaultViewLocationCache.Null;
			} else {
				ViewLocationCache = new DefaultViewLocationCache ();
			}
		}