Example #1
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");
        }
Example #2
0
        public void CallsToCssHandlerAreNotRepeated(string skinKey, string exptectedElements)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            MockRepository mocks = new MockRepository();

            VirtualPathProvider pathProvider = GetTemplatesPathProviderMock(mocks);
            mocks.ReplayAll();

            SkinTemplateCollection templates = new SkinTemplateCollection(pathProvider);
            StyleSheetElementCollectionRenderer renderer = new StyleSheetElementCollectionRenderer(templates);
            string styleElements = renderer.RenderStyleElementCollection(skinKey);
            SkinTemplate template = templates.GetTemplate(skinKey);
            Console.WriteLine(styleElements);

            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");
        }
Example #3
0
        public void StyleSheetElementCollectionRenderer_WithNoneMergeModeAndSecondaryStyle_RendersPlainCssLinkElements(
            string subFolder, string applicationPath, string expectedPrintCssPath, string expectedDefaultCssPath,
            string expectedSecondaryCssPath)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", subFolder, applicationPath);
            var pathProvider = new Mock<VirtualPathProvider>();
            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer = new StyleSheetElementCollectionRenderer(skinEngine);
            string styleElements = renderer.RenderStyleElementCollection("Lightz-light.css");

            string printCss =
                string.Format(@"<link media=""print"" type=""text/css"" rel=""stylesheet"" href=""{0}"" />",
                              expectedPrintCssPath);
            Assert.IsTrue(styleElements.Contains(printCss, StringComparison.OrdinalIgnoreCase),
                          "Expected the printcss to be there.");

            string defaultCss = string.Format(@"<link type=""text/css"" rel=""stylesheet"" href=""{0}"" />",
                                              expectedDefaultCssPath);
            Assert.IsTrue(styleElements.Contains(defaultCss, StringComparison.OrdinalIgnoreCase),
                          "Expected the default css to be there.");

            string secondaryCss = string.Format(@"<link type=""text/css"" rel=""stylesheet"" href=""{0}"" />",
                                                expectedSecondaryCssPath);
            Assert.IsTrue(styleElements.Contains(secondaryCss, StringComparison.OrdinalIgnoreCase),
                          "Expected the secondary css to be there.");
        }
Example #4
0
        public void StyleSheetElementCollectionRendererRendersMergedCssLinkElements(string subFolder,
            string applicationPath,
            string expectedPrintCssPath)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", subFolder, applicationPath);
            var pathProvider = new Mock<VirtualPathProvider>();
            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer = new StyleSheetElementCollectionRenderer(skinEngine);
            string styleElements = renderer.RenderStyleElementCollection("Piyo");

            string printCss =
                string.Format(
                    @"<link media=""screen"" type=""text/css"" rel=""stylesheet"" title=""fixed"" href=""{0}"" />",
                    expectedPrintCssPath);
            Assert.IsTrue(styleElements.Contains(printCss, StringComparison.OrdinalIgnoreCase),
                          "Expected the fixed screen css to be there.");
        }
Example #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");
            }
        }
Example #6
0
        public void RenderStyleElementCollection_WithNoStyles_RendersDefaultStyle()
        {
            // arrange
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", string.Empty, "/");
            var pathProvider = new Mock<VirtualPathProvider>();
            var skinEngine = new SkinEngine(pathProvider.Object);
            var renderer = new StyleSheetElementCollectionRenderer(skinEngine);
            var skinTemplate = new SkinTemplate {ExcludeDefaultStyle = false, Styles = null, TemplateFolder = "TestSkin"};

            // act
            string styleElements = renderer.RenderStyleElementCollection("TestSkin", skinTemplate);

            // assert
            const string defaultStyle = @"<link type=""text/css"" rel=""stylesheet"" href=""/Skins/TestSkin/style.css"" />";
            Assert.AreEqual(defaultStyle, styleElements.Trim());
        }
Example #7
0
        public void MergedCssDoesntContainStyleWithMediaAndTitle()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock<VirtualPathProvider>();
            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer = new StyleSheetElementCollectionRenderer(skinEngine);
            var mergedStyles = (List<StyleDefinition>)renderer.GetStylesToBeMerged("Piyo");

            Assert.IsFalse(mergedStyles.Contains(new StyleDefinition("/Skins/Piyo/piyo-fixed.css", "screen")),
                           "Skin Piyo should not have the fixed screen css in the merged CSS");
        }
Example #8
0
        public void MergedCssDoesntContainDefaultIfExcluded()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock<VirtualPathProvider>();
            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer = new StyleSheetElementCollectionRenderer(skinEngine);
            var mergedStyles = (List<StyleDefinition>)renderer.GetStylesToBeMerged("WPSkin");

            Assert.IsFalse(mergedStyles.Contains(new StyleDefinition("/Skins/WPSkin/style.css")),
                           "Skin WPSkin should not have the default style.css");
        }
Example #9
0
        public void MergedCssContainsStyleWithMedia()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            var pathProvider = new Mock<VirtualPathProvider>();
            pathProvider.SetupSkins();
            var skinEngine = new SkinEngine(pathProvider.Object);

            var renderer = new StyleSheetElementCollectionRenderer(skinEngine);
            var mergedStyles = (List<StyleDefinition>)renderer.GetStylesToBeMerged("Piyo");

            Assert.IsTrue(mergedStyles.Contains(new StyleDefinition("/Skins/Piyo/print.css", "print")),
                          "Skin Piyo should have the print css in the merged css");
        }
Example #10
0
        public void StyleSheetElementCollectionRendererRendersPlainCssLinkElementsWithNoneMergeModeAndSecondaryStyle(string subFolder, string applicationPath, string expectedPrintCssPath, string expectedDefaultCssPath, string expectedSecondaryCssPath)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", subFolder, applicationPath);
            MockRepository mocks = new MockRepository();

            VirtualPathProvider pathProvider = GetTemplatesPathProviderMock(mocks);
            mocks.ReplayAll();

            SkinTemplateCollection templates = new SkinTemplateCollection(pathProvider);
            StyleSheetElementCollectionRenderer renderer = new StyleSheetElementCollectionRenderer(templates);
            string styleElements = renderer.RenderStyleElementCollection("Nature-rain.css");

            Console.WriteLine(styleElements);

            string printCss = string.Format(@"<link media=""print"" type=""text/css"" rel=""stylesheet"" href=""{0}"" />", expectedPrintCssPath);
            Assert.IsTrue(styleElements.IndexOf(printCss) > -1, "Expected the printcss to be there.");

            string defaultCss = string.Format(@"<link type=""text/css"" rel=""stylesheet"" href=""{0}"" />", expectedDefaultCssPath);
            Assert.IsTrue(styleElements.IndexOf(defaultCss) > -1, "Expected the default css to be there.");

            string secondaryCss = string.Format(@"<link type=""text/css"" rel=""stylesheet"" href=""{0}"" />", expectedSecondaryCssPath);
            Assert.IsTrue(styleElements.IndexOf(secondaryCss) > -1, "Expected the secondary css to be there.");
        }
Example #11
0
        public void StyleSheetElementCollectionRendererRendersMergedCssLinkElements(string subFolder, string applicationPath, string expectedPrintCssPath)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", subFolder, applicationPath);
            MockRepository mocks = new MockRepository();

            VirtualPathProvider pathProvider = GetTemplatesPathProviderMock(mocks);
            mocks.ReplayAll();

            SkinTemplateCollection templates = new SkinTemplateCollection(pathProvider);
            StyleSheetElementCollectionRenderer renderer = new StyleSheetElementCollectionRenderer(templates);
            string styleElements = renderer.RenderStyleElementCollection("Piyo");

            Console.WriteLine(styleElements);

            string printCss = string.Format(@"<link media=""screen"" type=""text/css"" rel=""stylesheet"" title=""fixed"" href=""{0}"" />", expectedPrintCssPath);
            Assert.IsTrue(styleElements.IndexOf(printCss) > -1, "Expected the fixed screen css to be there.");
        }
Example #12
0
        public void StyleSheetElementCollectionRendererRendersLinkElementsInRightOrder(string skinKey, bool expectedFirst)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            MockRepository mocks = new MockRepository();

            VirtualPathProvider pathProvider = GetTemplatesPathProviderMock(mocks);
            mocks.ReplayAll();

            SkinTemplateCollection templates = new SkinTemplateCollection(pathProvider);
            StyleSheetElementCollectionRenderer renderer = new StyleSheetElementCollectionRenderer(templates);

            string styleElements = renderer.RenderStyleElementCollection(skinKey);
            SkinTemplate template = templates.GetTemplate(skinKey);

            Console.WriteLine(styleElements);
            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), "Merged CSS is not in first position");
            else
                Assert.IsTrue(styleElements.EndsWith(mergedCss), "Merged CSS is not in last position");
        }
Example #13
0
        public void MergedCssIsCorrect(string skinKey, int expectedStyles)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            MockRepository mocks = new MockRepository();

            VirtualPathProvider pathProvider = GetTemplatesPathProviderMock(mocks);
            mocks.ReplayAll();

            SkinTemplateCollection templates = new SkinTemplateCollection(pathProvider);
            StyleSheetElementCollectionRenderer renderer = new StyleSheetElementCollectionRenderer(templates);
            int mergedStyles = renderer.GetStylesToBeMerged(skinKey).Count;

            Assert.AreEqual(expectedStyles, mergedStyles, String.Format("Skin {0} should have {1} merged styles but found {2}", skinKey, expectedStyles, mergedStyles));
        }
Example #14
0
        public void MergedCssDoesntContainStyleWithMediaAndTitle()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            MockRepository mocks = new MockRepository();

            VirtualPathProvider pathProvider = GetTemplatesPathProviderMock(mocks);
            mocks.ReplayAll();

            SkinTemplateCollection templates = new SkinTemplateCollection(pathProvider);
            StyleSheetElementCollectionRenderer renderer = new StyleSheetElementCollectionRenderer(templates);
            List<StyleDefinition> mergedStyles = (List<StyleDefinition>)renderer.GetStylesToBeMerged("Piyo");

            Assert.IsFalse(mergedStyles.Contains(new StyleDefinition("/Skins/Piyo/piyo-fixed.css", "screen")), "Skin Piyo should not have the fixed screen css in the merged CSS");
        }
Example #15
0
        public void MergedCssDoesntContainDefaultIfExcluded()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "blog", string.Empty);
            MockRepository mocks = new MockRepository();

            VirtualPathProvider pathProvider = GetTemplatesPathProviderMock(mocks);
            mocks.ReplayAll();

            SkinTemplateCollection templates = new SkinTemplateCollection(pathProvider);
            StyleSheetElementCollectionRenderer renderer = new StyleSheetElementCollectionRenderer(templates);
            List<StyleDefinition> mergedStyles = (List<StyleDefinition>)renderer.GetStylesToBeMerged("WPSkin");

            Assert.IsFalse(mergedStyles.Contains(new StyleDefinition("/Skins/WPSkin/style.css")), "Skin WPSkin should not have the default style.css");
        }