Пример #1
0
        public void GetSkinTemplates_WithFolders_ReturnsSkinPerFolder()
        {
            //arrange
            var directories = new List <VirtualDirectory>();

            for (int i = 0; i < 3; i++)
            {
                var skinDir = new Mock <VirtualDirectory>("~/skins/skin" + i);
                skinDir.Setup(d => d.Name).Returns("Skin" + i);
                directories.Add(skinDir.Object);
            }
            var skinsDir = new Mock <VirtualDirectory>("~/skins");

            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock <VirtualPathProvider>();

            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary <string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(false /* mobile */);

            //assert
            Assert.AreEqual(3, skinTemplates.Count);
            Assert.AreEqual("Skin0", skinTemplates.Values.First().Name);
            Assert.AreEqual("Skin0", skinTemplates.Values.First().TemplateFolder);
        }
Пример #2
0
        public void GetSkinTemplates_WithSpecialFolders_IgnoresSpecialFolders()
        {
            //arrange
            var directories = new List <VirtualDirectory>();
            var nonSkinDir  = new Mock <VirtualDirectory>("~/skins/_system");

            nonSkinDir.Setup(d => d.Name).Returns("_system");
            directories.Add(nonSkinDir.Object);
            var skinDir = new Mock <VirtualDirectory>("~/skins/skin1");

            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock <VirtualDirectory>("~/skins");

            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock <VirtualPathProvider>();

            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary <string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(false /* mobile */);

            //assert
            Assert.AreEqual(1, skinTemplates.Count);
            Assert.AreEqual("Skin1", skinTemplates.Values.First().Name);
        }
Пример #3
0
        public void GetSkinTemplates_WithMobileOnlyTrue_DoesNotReturnSkinThatDoesNotSupportMobile()
        {
            //arrange
            var virtualFile = new Mock<VirtualFile>("~/skins/skin1/skin.config");
            Stream stream =
                @"<?xml version=""1.0""?>
    <SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
        <SkinTemplate Name=""Skinny"" MobileSupported=""None"">
          <Styles>
            <Style href=""~/skins/_System/commonstyle.css"" />
          </Styles>
        </SkinTemplate>
    </SkinTemplates>"
                    .ToStream();
            virtualFile.Setup(vf => vf.Open()).Returns(stream);

            var directories = new List<VirtualDirectory>();
            var skinDir = new Mock<VirtualDirectory>("~/skins/skin1");
            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            vpp.Setup(v => v.FileExists("~/skins/Skin1/skin.config")).Returns(true);
            vpp.Setup(v => v.GetFile("~/skins/Skin1/skin.config")).Returns(virtualFile.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(mobileOnly: true);

            //assert
            Assert.AreEqual(0, skinTemplates.Count);
        }
Пример #4
0
        public void CanGetMergeModeAttribute()
        {
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);
            IDictionary <string, SkinTemplate> templates = skinEngine.GetSkinTemplates(false /* mobile */);

            SkinTemplate templateWithMergedFirstMergeMode = templates["Semagogy"];

            Assert.AreEqual(StyleMergeMode.MergedFirst, templateWithMergedFirstMergeMode.StyleMergeMode,
                            "MergeMode should be MergedFirst.");

            SkinTemplate templateWithMergedAfterMergeMode = templates["RedBook-Green.css"];

            Assert.AreEqual(StyleMergeMode.MergedAfter, templateWithMergedAfterMergeMode.StyleMergeMode,
                            "MergeMode should be MergedAfter.");

            SkinTemplate templateWithNoneMergeMode = templates["RedBook-Red.css"];

            Assert.AreEqual(StyleMergeMode.None, templateWithNoneMergeMode.StyleMergeMode, "MergeMode should be None.");

            Assert.AreNotEqual(StyleMergeMode.MergedAfter, templateWithNoneMergeMode.StyleMergeMode,
                               "MergeMode should not be MergedAfter.");

            SkinTemplate templateWithoutMergeMode = templates["RedBook-Blue.css"];

            Assert.AreEqual(StyleMergeMode.None, templateWithoutMergeMode.StyleMergeMode, "MergeMode should be None.");
        }
Пример #5
0
        public void StyleSheetElementCollectionRendererRendersLinkElementsInRightOrder(string skinKey,
                                                                                       bool expectedFirst)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer = new StyleSheetElementCollectionRenderer(skinEngine);

            string       styleElements = renderer.RenderStyleElementCollection(skinKey);
            SkinTemplate template      = skinEngine.GetSkinTemplates(false)[skinKey];

            styleElements = styleElements.Trim('\r', '\n');
            string mergedCss = @"<link type=""text/css"" rel=""stylesheet"" href=""/Skins/" + template.TemplateFolder +
                               "/css.axd?name=" + skinKey + @""" />";

            if (expectedFirst)
            {
                Assert.IsTrue(styleElements.StartsWith(mergedCss, StringComparison.OrdinalIgnoreCase),
                              "Merged CSS is not in first position");
            }
            else
            {
                Assert.IsTrue(styleElements.EndsWith(mergedCss, StringComparison.OrdinalIgnoreCase),
                              "Merged CSS is not in last position");
            }
        }
        public void ScriptsWithParametricSrcAreNotMerged()
        {
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);
            IDictionary <string, SkinTemplate> templates = skinEngine.GetSkinTemplates(false /* mobile */);
            SkinTemplate template    = templates["Piyo"];
            bool         canBeMerged = ScriptElementCollectionRenderer.CanScriptsBeMerged(template);

            Assert.IsFalse(canBeMerged, "Skins with scripts that have query string parameters should not be mergeable.");
        }
        public void ScriptsWithNoneScriptMergeModeAreNotMerged()
        {
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);
            IDictionary <string, SkinTemplate> templates = skinEngine.GetSkinTemplates(false /* mobile */);
            SkinTemplate template    = templates["Semagogy"];
            bool         canBeMerged = ScriptElementCollectionRenderer.CanScriptsBeMerged(template);

            Assert.IsFalse(canBeMerged, "Skins with ScriptMergeMode=\"DontMerge\" should not be mergeable.");
        }
Пример #8
0
        protected void OnSaveSkinClicked()
        {
            Blog         blog         = SubtextContext.Blog;
            var          skinEngine   = new SkinEngine();
            SkinTemplate skinTemplate =
                skinEngine.GetSkinTemplates(false /* mobile */).ItemOrNull(Request.Form["SkinKey"]);

            blog.Skin.TemplateFolder = skinTemplate.TemplateFolder;
            blog.Skin.SkinStyleSheet = skinTemplate.StyleSheet;
            Repository.UpdateConfigData(blog);

            BindLocalUI();
        }
Пример #9
0
        private SkinViewModel GetSkinFromSkinKey(string skinKey, bool mobileOnly)
        {
            var skinEngine   = new SkinEngine();
            var skins        = skinEngine.GetSkinTemplates(mobileOnly: mobileOnly);
            var skinTemplate = skins.GetValueOrDefault(skinKey ?? "Naked");

            if (skinTemplate == null)
            {
                skinTemplate = skins.First().Value;
            }
            return(new SkinViewModel {
                name = skinTemplate.Name, icon = GetSkinIconImage(skinTemplate), skinKey = skinTemplate.SkinKey, mobile = mobileOnly
            });
        }
Пример #10
0
        public void GetSkinTemplates_WithSkinConfigInFolder_AppliesConfig()
        {
            //arrange
            var    virtualFile = new Mock <VirtualFile>("~/skins/skin1/skin.config");
            Stream stream      =
                @"<?xml version=""1.0""?>
<SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
    <SkinTemplate Name=""Skinny"" StyleMergeMode=""MergedAfter"" ScriptMergeMode=""Merge"">
      <Styles>
        <Style href=""~/skins/_System/commonstyle.css"" />
      </Styles>
    </SkinTemplate>
</SkinTemplates>"
                .ToStream();

            virtualFile.Setup(vf => vf.Open()).Returns(stream);

            var directories = new List <VirtualDirectory>();
            var skinDir     = new Mock <VirtualDirectory>("~/skins/skin1");

            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock <VirtualDirectory>("~/skins");

            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock <VirtualPathProvider>();

            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            vpp.Setup(v => v.FileExists("~/skins/Skin1/skin.config")).Returns(true);
            vpp.Setup(v => v.GetFile("~/skins/Skin1/skin.config")).Returns(virtualFile.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary <string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(false /* mobile */);

            //assert
            Assert.AreEqual(1, skinTemplates.Count);
            SkinTemplate template = skinTemplates.Values.First();

            Assert.AreEqual("Skinny", template.Name);
            Assert.AreEqual("Skin1", template.TemplateFolder);
            Assert.AreEqual(StyleMergeMode.MergedAfter, template.StyleMergeMode);
            Assert.AreEqual(ScriptMergeMode.Merge, template.ScriptMergeMode);
            Assert.AreEqual(1, template.Styles.Count());
        }
Пример #11
0
        public void CallsToCssHandlerAreNotRepeated(string skinKey, string exptectedElements)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var    renderer      = new StyleSheetElementCollectionRenderer(skinEngine);
            string styleElements = renderer.RenderStyleElementCollection(skinKey);
            IDictionary <string, SkinTemplate> templates = skinEngine.GetSkinTemplates(false);
            SkinTemplate template = templates[skinKey];

            string mergedCss = @"<link type=""text/css"" rel=""stylesheet"" href=""/Skins/" + template.TemplateFolder +
                               "/css.axd?name=" + skinKey + @""" />";

            styleElements = styleElements.Replace(mergedCss, string.Empty);
            Assert.IsTrue(styleElements.Trim('\r', '\n').Equals(exptectedElements), "Not the expected stylesheet links");
        }
        public void CanGetScriptMergeModeAttribute()
        {
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);
            IDictionary <string, SkinTemplate> templates = skinEngine.GetSkinTemplates(false /* mobile */);

            SkinTemplate templateWithMergeScriptMergeMode = templates["Piyo"];

            Assert.IsTrue(templateWithMergeScriptMergeMode.MergeScripts, "ScriptMergeMode should be Merge.");

            SkinTemplate templateWithDontMergeScriptMergeMode = templates["Semagogy"];

            Assert.IsFalse(templateWithDontMergeScriptMergeMode.MergeScripts, "ScriptMergeMode should be DontMerge.");

            SkinTemplate templateWithoutScriptMergeMode = templates["RedBook-Green.css"];

            Assert.IsFalse(templateWithoutScriptMergeMode.MergeScripts, "ScriptMergeMode should be None.");
        }
Пример #13
0
        public void CanGetExcludeDefaultStyleAttribute()
        {
            var pathProvider = new Mock <VirtualPathProvider>();

            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);
            IDictionary <string, SkinTemplate> templates = skinEngine.GetSkinTemplates(false /* mobile */);

            SkinTemplate templateWithTrueExcludedDefault = templates["RedBook-Blue.css"];

            Assert.IsTrue(templateWithTrueExcludedDefault.ExcludeDefaultStyle, "ExcludeDefaultStyle should be True.");

            SkinTemplate templateWithFalseExcludedDefault = templates["Gradient"];

            Assert.IsFalse(templateWithFalseExcludedDefault.ExcludeDefaultStyle, "ExcludeDefaultStyle should be false.");

            SkinTemplate templateWithoutExcludedDefault = templates["Piyo"];

            Assert.IsFalse(templateWithoutExcludedDefault.ExcludeDefaultStyle, "ExcludeDefaultStyle should be false.");
        }
Пример #14
0
        public ActionResult Save(string skinKey, bool mobile)
        {
            Blog         blog         = SubtextContext.Blog;
            var          skinEngine   = new SkinEngine();
            SkinTemplate skinTemplate =
                skinEngine.GetSkinTemplates(mobile).GetValueOrDefault(skinKey);

            if (!mobile)
            {
                blog.Skin.TemplateFolder = skinTemplate.TemplateFolder;
                blog.Skin.SkinStyleSheet = skinTemplate.StyleSheet;
            }
            else
            {
                blog.MobileSkin.TemplateFolder = skinTemplate.TemplateFolder;
                blog.MobileSkin.SkinStyleSheet = skinTemplate.StyleSheet;
            }
            SubtextContext.Repository.UpdateConfigData(blog);

            return(Json(new { }));
        }