示例#1
0
        public void GetResource_ReturnsCorrectResource()
        {
            // if the current folder has the file, give the current folder's file
            Assert.AreEqual("current", Themes.GetResourcePath("current", "default", "folder", "foo.cs", GetResourceHelperMethod));

            // if current folder doesn't but default does, fall through to the default's file
            Assert.AreEqual("fallthrough", Themes.GetResourcePath("bad", "default", "folder", "foo.cs", GetResourceHelperMethod));

            // if neither have them, the result should be null
            Assert.IsNull(Themes.GetResourcePath("bad", "bad", "folder", "foo.cs", GetResourceHelperMethod));
        }
示例#2
0
        private static MvcHtmlString RenderThemedContent(this HtmlHelper helper, ActionModel actionModel, bool fallbackToNonThemedVersion = true)
        {
            string path = Themes.GetResourcePath("Partials", string.Concat(actionModel.ViewName, ".cshtml"));

            if (!File.Exists(HttpContext.Current.Server.MapPath(path)) && fallbackToNonThemedVersion)
            {
                return(helper.Partial(actionModel.ViewName, actionModel.ViewData));
            }
            return(helper.Partial(path, actionModel.ViewData));
            //return(((WebPageBase)helper.ViewContext.View).RenderPage(Themes.GetResourcePath("Partials", string.Concat(partialViewName, ".cshtml")), data));
        }
示例#3
0
        public void InitializationTests()
        {
            // Ensure that these properties are invoked only through this method since they are static. Any call that involves using the value
            // of these properties are flaky after this call.


            // Attempt to read properties before initialization
            ExceptionAssert.Throws <InvalidOperationException>(() => Themes.CurrentTheme = "Foo",
                                                               @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            ExceptionAssert.Throws <InvalidOperationException>(() => { var x = Themes.CurrentTheme; },
                                                               @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            ExceptionAssert.Throws <InvalidOperationException>(() => { var x = Themes.AvailableThemes; },
                                                               @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            ExceptionAssert.Throws <InvalidOperationException>(() => { var x = Themes.DefaultTheme; },
                                                               @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            ExceptionAssert.Throws <InvalidOperationException>(() => { var x = Themes.GetResourcePath("baz"); },
                                                               @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            ExceptionAssert.Throws <InvalidOperationException>(() => { var x = Themes.GetResourcePath("baz", "some-file"); },
                                                               @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");


            var defaultTheme   = "default-theme";
            var themeDirectory = "theme-directory";

            Themes.Initialize(themeDirectory: themeDirectory, defaultTheme: defaultTheme);

            // Ensure Theme use scope storage to store properties
            Assert.AreEqual(ScopeStorage.CurrentScope[Themes._themesInitializedKey], true);
            Assert.AreEqual(ScopeStorage.CurrentScope[Themes._themeDirectoryKey], themeDirectory);
            Assert.AreEqual(ScopeStorage.CurrentScope[Themes._defaultThemeKey], defaultTheme);

            // CurrentTheme falls back to default theme when null
            Assert.AreEqual(Themes.CurrentTheme, defaultTheme);

            var value = "random-value";

            Themes.CurrentTheme = value;
            Assert.AreEqual(Themes.CurrentTheme, value);
            Assert.AreEqual(ScopeStorage.CurrentScope[Themes._currentThemeKey], value);
        }
示例#4
0
        private static XElement getLayoutMap()
        {
            XElement contentMap = null;
            string   layoutPath = string.Concat(AppConfiguration.ActiveLayoutName, ".xml"); // make the file observable

            layoutPath = Themes.GetResourcePath("Layouts", layoutPath);                     //automatic fallback to default theme

            if (cache.Contains(layoutPath))
            {
                contentMap = (XElement)cache[layoutPath];
            }
            else
            {
                string fullpath = HttpContext.Current.Server.MapPath(layoutPath);
                contentMap = XElement.Load(fullpath);
                cache.Add(layoutPath, contentMap, DateTimeOffset.Now.AddHours(24));
            }
            return(contentMap);
        }
示例#5
0
        public static string GetLayoutName(this HtmlHelper helper)
        {
            string layoutName = "~/Views/Shared/_Layout.cshtml"; // built-in layout
            var    request    = helper.ViewContext.HttpContext.Request;
            var    session    = helper.ViewContext.HttpContext.Session;

            if (AppConfiguration.IsPostBack(request) && !string.IsNullOrWhiteSpace(request["Theme"]))
            {
                Themes.CurrentTheme     = request["Theme"];
                session["CurrentTheme"] = Themes.CurrentTheme;
            }
            else if (session["CurrentTheme"] != null)
            {
                Themes.CurrentTheme = session["CurrentTheme"] as string;
            }
            string layoutFileName = string.Concat(AppConfiguration.ActiveLayoutName, ".cshtml");

            layoutFileName = Themes.GetResourcePath("Layouts", layoutFileName); // Auto fallback to DefaultTheme
            if (!string.IsNullOrWhiteSpace(layoutFileName))
            {
                layoutName = layoutFileName;
            }
            return(layoutName);
        }