Beispiel #1
0
        public void GivenBundleWithMediaAndAssets_WhenRender_ThenLinkForEachAssetIsReturned()
        {
            var bundle = new StylesheetBundle("~/test")
            {
                Media = "MEDIA"
            };

            bundle.Assets.Add(Mock.Of <IAsset>());
            bundle.Assets.Add(Mock.Of <IAsset>());

            var urlGenerator = new Mock <IUrlGenerator>();
            var assetUrls    = new Queue <string>(new[] { "asset1", "asset2" });

            urlGenerator.Setup(g => g.CreateAssetUrl(It.IsAny <IAsset>()))
            .Returns(assetUrls.Dequeue);

            var renderer = new DebugStylesheetHtmlRenderer(urlGenerator.Object);
            var html     = renderer.Render(bundle);

            html.ShouldEqual(
                "<link href=\"asset1\" type=\"text/css\" rel=\"stylesheet\" media=\"MEDIA\"/>" +
                Environment.NewLine +
                "<link href=\"asset2\" type=\"text/css\" rel=\"stylesheet\" media=\"MEDIA\"/>"
                );
        }
Beispiel #2
0
        public void GivenStylesheetCondition_WhenRender_ThenConditionalCommentWrapsLinks()
        {
            var bundle = new StylesheetBundle("~/test")
            {
                Condition = "CONDITION"
            };

            bundle.Assets.Add(Mock.Of <IAsset>());
            bundle.Assets.Add(Mock.Of <IAsset>());

            var urlGenerator = new Mock <IUrlGenerator>();
            var assetUrls    = new Queue <string>(new[] { "asset1", "asset2" });

            urlGenerator.Setup(g => g.CreateAssetUrl(It.IsAny <IAsset>()))
            .Returns(assetUrls.Dequeue);

            var renderer = new DebugStylesheetHtmlRenderer(urlGenerator.Object);
            var html     = renderer.Render(bundle);

            html.ShouldEqual(
                "<!--[if CONDITION]>" + Environment.NewLine +
                "<link href=\"asset1\" type=\"text/css\" rel=\"stylesheet\"/>" +
                Environment.NewLine +
                "<link href=\"asset2\" type=\"text/css\" rel=\"stylesheet\"/>" + Environment.NewLine +
                "<![endif]-->"
                );
        }
        public void ProcessAddsReferencesToLessAssetInBundle()
        {
            var asset = new Mock <IAsset>();

            asset.SetupGet(a => a.SourceFile.FullPath).Returns("~/asset.less");

            var lessSource = @"
// @reference ""another1.less"";
// @reference '/another2.less';
// @reference '../test/another3.less';
";

            asset.Setup(a => a.OpenStream())
            .Returns(lessSource.AsStream());
            var bundle = new StylesheetBundle("~");

            bundle.Assets.Add(asset.Object);

            var processor = new ParseLessReferences();

            processor.Process(bundle, new CassetteSettings(""));

            asset.Verify(a => a.AddReference("another1.less", 2));
            asset.Verify(a => a.AddReference("/another2.less", 3));
            asset.Verify(a => a.AddReference("../test/another3.less", 4));
        }
        public StylesheetPipeline_Process_TestBase()
        {
            settings = new CassetteSettings();
            bundle = new StylesheetBundle("~");
            asset1 = new Mock<IAsset>();
            asset2 = new Mock<IAsset>();
            bundle.Assets.Add(asset1.Object);
            bundle.Assets.Add(asset2.Object);

            asset1.SetupGet(a => a.Path)
                  .Returns("~/asset1.css");
            asset1.Setup(a => a.OpenStream())
                  .Returns(() => "/* @reference \"asset2.css\"; */".AsStream());
            asset2.SetupGet(a => a.Path)
                  .Returns("~/asset2.css");
            asset2.Setup(a => a.OpenStream())
                  .Returns(() => "p { color: White; }".AsStream());
            asset1.SetupGet(a => a.References)
                  .Returns(new[] { new AssetReference(asset1.Object.Path, "~/asset2.css", -1, AssetReferenceType.SameBundle) });

            minifier = new MicrosoftStylesheetMinifier();
            urlGenerator = new Mock<IUrlGenerator>();
            container = new TinyIoCContainer();
            container.Register(minifier);
            container.Register(urlGenerator.Object);
            container.Register(settings);
        }
        public void GivenStylesheetCondition_WhenRender_ThenConditionalCommentWrapsLinks()
        {
            var bundle = new StylesheetBundle("~/test")
            {
                Condition = "CONDITION"
            };
            bundle.Assets.Add(new StubAsset());
            bundle.Assets.Add(new StubAsset());

            var urlGenerator = new Mock<IUrlGenerator>();
            var assetUrls = new Queue<string>(new[] { "asset1", "asset2" });
            urlGenerator.Setup(g => g.CreateAssetUrl(It.IsAny<IAsset>(), It.IsAny<bool>()))
                        .Returns(assetUrls.Dequeue);

            var renderer = new DebugStylesheetHtmlRenderer(urlGenerator.Object);
            var html = renderer.Render(bundle);

            html.ShouldEqual(
                "<!--[if CONDITION]>" + Environment.NewLine +
                "<link href=\"asset1\" type=\"text/css\" rel=\"stylesheet\"/>" +
                Environment.NewLine +
                "<link href=\"asset2\" type=\"text/css\" rel=\"stylesheet\"/>" + Environment.NewLine +
                "<![endif]-->"
            );
        }
Beispiel #6
0
        public StylesheetPipeline_Process_TestBase()
        {
            settings = new CassetteSettings();
            bundle   = new StylesheetBundle("~");
            asset1   = new Mock <IAsset>();
            asset2   = new Mock <IAsset>();
            bundle.Assets.Add(asset1.Object);
            bundle.Assets.Add(asset2.Object);

            asset1.SetupGet(a => a.Path)
            .Returns("~/asset1.css");
            asset1.Setup(a => a.OpenStream())
            .Returns(() => "/* @reference \"asset2.css\"; */".AsStream());
            asset2.SetupGet(a => a.Path)
            .Returns("~/asset2.css");
            asset2.Setup(a => a.OpenStream())
            .Returns(() => "p { color: White; }".AsStream());
            asset1.SetupGet(a => a.References)
            .Returns(new[] { new AssetReference(asset1.Object.Path, "~/asset2.css", -1, AssetReferenceType.SameBundle) });

            minifier     = new MicrosoftStylesheetMinifier();
            urlGenerator = new Mock <IUrlGenerator>();
            container    = new TinyIoCContainer();
            container.Register(minifier);
            container.Register(urlGenerator.Object);
            container.Register(settings);
        }
        StylesheetBundle StubBundle(Mock <IAsset> asset)
        {
            var bundle = new StylesheetBundle("~");

            bundle.Assets.Add(asset.Object);
            return(bundle);
        }
Beispiel #8
0
 static StylesheetBundle StubStylesheetBundle(string path)
 {
     var bundle = new StylesheetBundle(path);
     var asset = new Mock<IAsset>();
     asset.SetupGet(a => a.Hash).Returns(new byte[] { 1, 2, 3 });
     bundle.Assets.Add(asset.Object);
     return bundle;
 }
 static StylesheetBundle StubStylesheetBundle(string path)
 {
     var bundle = new StylesheetBundle(path)
     {
         Hash = new byte[] { 1, 2, 3 }
     };
     return bundle;
 }
Beispiel #10
0
        public void WhenProcessBundle_ThenHashIsAssigned()
        {
            var pipeline = new StylesheetPipeline();
            var bundle   = new StylesheetBundle("~");

            pipeline.Process(bundle, new CassetteSettings(""));

            bundle.Hash.ShouldNotBeNull();
        }
        Mock<IAsset> AddCssAsset(StylesheetBundle bundle, string css)
        {
            var asset = new Mock<IAsset>();
            bundle.Assets.Add(asset.Object);

            asset.SetupGet(a => a.Path).Returns("asset.css");
            asset.Setup(a => a.OpenStream()).Returns(() => css.AsStream());
            return asset;
        }
        void AssertPipelineContains <T>() where T : IBundleProcessor <Bundle>
        {
            // MutablePipeline steps are actually created when Process is called.
            var bundle = new StylesheetBundle("~");

            pipeline.Process(bundle, new CassetteSettings(""));

            pipeline.CreatedPipeline.OfType <T>().ShouldNotBeEmpty();
        }
        public void GivenProductionMode_WhenProcess_ThenBundleRenderIsStylesheetHtmlRenderer()
        {
            var processor = new AssignStylesheetsRenderer();
            var settings = new CassetteSettings { IsDebuggingEnabled = false };
            var bundle = new StylesheetBundle("~/test");

            processor.Process(bundle, settings);

            bundle.Renderer.ShouldBeType<StylesheetHtmlRenderer>();
        }
        public void Configure(BundleCollection bundles, CassetteSettings settings)
        {
            var script = new ScriptBundle("cassette.web.jasmine");
            script.Assets.Add(new ResourceAsset("Cassette.Web.Jasmine.jasmine.js", GetType().Assembly));
            bundles.Add(script);

            var css = new StylesheetBundle("cassette.web.jasmine");
            css.Assets.Add(new ResourceAsset("Cassette.Web.Jasmine.jasmine.css", GetType().Assembly));
            bundles.Add(css);
        }
        public void GivenDebugMode_WhenProcess_ThenBundleRenderIsDebugStylesheetHtmlRenderer()
        {
            var settings = new CassetteSettings { IsDebuggingEnabled = true };
            var processor = new AssignStylesheetRenderer(Mock.Of<IUrlGenerator>(), settings);
            var bundle = new StylesheetBundle("~/test");

            processor.Process(bundle);

            bundle.Renderer.ShouldBeType<DebugStylesheetHtmlRenderer>();
        }
Beispiel #16
0
        public void WhenProcessBundle_ThenHashIsAssigned()
        {
            var bundle = new StylesheetBundle("~");

            var pipeline = new StylesheetPipeline(container, settings);

            pipeline.Process(bundle);

            bundle.Hash.ShouldNotBeNull();
        }
Beispiel #17
0
        public void ProcessCallsProcessor()
        {
            var bundle = new StylesheetBundle("~");
            var processor = new Mock<IBundleProcessor<StylesheetBundle>>();
            bundle.Processor = processor.Object;

            bundle.Process(new CassetteSettings());

            processor.Verify(p => p.Process(bundle, It.IsAny<CassetteSettings>()));
        }
Beispiel #18
0
        public void ProcessCallsProcessor()
        {
            var bundle = new StylesheetBundle("~");
            var pipeline = new Mock<IBundlePipeline<StylesheetBundle>>();
            bundle.Pipeline = pipeline.Object;

            bundle.Process(new CassetteSettings());

            pipeline.Verify(p => p.Process(bundle));
        }
Beispiel #19
0
        Mock <IAsset> AddCssAsset(StylesheetBundle bundle, string css)
        {
            var asset = new Mock <IAsset>();

            bundle.Assets.Add(asset.Object);

            asset.SetupGet(a => a.SourceFile.FullPath).Returns("asset.css");
            asset.Setup(a => a.OpenStream()).Returns(() => css.AsStream());
            return(asset);
        }
Beispiel #20
0
        public void ProcessCallsProcessor()
        {
            var bundle    = new StylesheetBundle("~");
            var processor = new Mock <IBundleProcessor <StylesheetBundle> >();

            bundle.Processor = processor.Object;

            bundle.Process(new CassetteSettings());

            processor.Verify(p => p.Process(bundle, It.IsAny <CassetteSettings>()));
        }
Beispiel #21
0
        public static StylesheetBundle EmbedFonts(this StylesheetBundle bundle, Func <string, bool> shouldEmbedUrl)
        {
            var pipeline = bundle.Pipeline;
            var index    = pipeline.IndexOf <ExpandCssUrls>();

            pipeline.Insert <ConvertFontUrlsToDataUris.Factory>(
                index,
                factory => factory(shouldEmbedUrl)
                );
            return(bundle);
        }
        public void WhenProcessSimpleCssReferenceWithSingleQuotes_ThenAssetAddReferenceIsCalled()
        {
            var bundle = new StylesheetBundle("~");
            var css = "/* @reference 'test.css'; */";
            var asset = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();
            processor.Process(bundle, new CassetteSettings());

            asset.Verify(a => a.AddReference("test.css", 1));
        }
        public void WhenProcessCssReferenceWithoutTrailingSemicolon_ThenAssetAddReferenceIsCalled()
        {
            var bundle = new StylesheetBundle("~");
            var css = "/* @reference \"test.css\" */";
            var asset = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();
            processor.Process(bundle, new CassetteSettings());

            asset.Verify(a => a.AddReference("test.css", 1));
        }
Beispiel #24
0
        public void ProcessCallsProcessor()
        {
            var bundle   = new StylesheetBundle("~");
            var pipeline = new Mock <IBundlePipeline <StylesheetBundle> >();

            bundle.Pipeline = pipeline.Object;

            bundle.Process(new CassetteSettings());

            pipeline.Verify(p => p.Process(bundle));
        }
 static StylesheetBundle CreateStylesheetBundle()
 {
     var bundle = new StylesheetBundle("~");
     var asset = new StubAsset(
         "~/asset.css",
         ".a { background-image:url(image-a.png);background-repeat:no-repeat;width:20px;height:20px }\n" +
         ".b { background-image:url(image-b.png);background-repeat:no-repeat;width:20px;height:20px }"
         );
     bundle.Assets.Add(asset);
     return bundle;
 }
        public void WhenProcessSimpleCssReference_ThenAssetAddReferenceIsCalled()
        {
            var bundle = new StylesheetBundle("~");
            var css = "/* @reference \"test.css\"; */";
            var asset = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();
            processor.Process(bundle);

            asset.Verify(a => a.AddReference("test.css", 1));
        }
Beispiel #27
0
        public StylesheetBundleSerializer_Tests()
        {
            bundle = new StylesheetBundle("~")
            {
                Hash      = new byte[0],
                Media     = "MEDIA",
                Condition = "CONDITION",
                Renderer  = new StylesheetHtmlRenderer(Mock.Of <IUrlGenerator>())
            };

            WriteToElement();
        }
        public void WhenModifiedPipelineProcessesBundle_ThenLessAssetHasCompileAssetTransformAdded()
        {
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.Path).Returns("~/file.less");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            var bundle = new StylesheetBundle("~");
            bundle.Assets.Add(asset.Object);

            modifiedPipeline.Process(bundle);

            asset.Verify(a => a.AddAssetTransformer(It.Is<IAssetTransformer>(t => t is CompileAsset)));
        }
        public SpritingIntegrationTest()
        {
            container = CreateContainer();
            cache = new TempDirectory();
            InitDirectories();

            bundle = CreateStylesheetBundle();

            // SpriteImages expects image URLs to be expanded into absolute Cassette file URLs.
            ExpandUrls(bundle);
            SpriteImages(bundle);
        }
        public StylesheetBundleSerializer_Tests()
        {
            bundle = new StylesheetBundle("~")
            {
                Hash      = new byte[0],
                Media     = "MEDIA",
                Condition = "CONDITION",
                Renderer  = new ConstantHtmlRenderer <StylesheetBundle>("", new VirtualDirectoryPrepender("/"))
            };

            WriteToElement();
        }
        public StylesheetBundleSerializer_Tests()
        {
            bundle = new StylesheetBundle("~")
            {
                Hash = new byte[0],
                Media = "MEDIA",
                Condition = "CONDITION",
                Renderer = new StylesheetHtmlRenderer(Mock.Of<IUrlGenerator>())
            };

            WriteToElement();
        }
Beispiel #32
0
        public void WhenProcessSimpleCssReference_ThenAssetAddReferenceIsCalled()
        {
            var bundle = new StylesheetBundle("~");
            var css    = "/* @reference \"test.css\"; */";
            var asset  = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();

            processor.Process(bundle);

            asset.Verify(a => a.AddReference("test.css", 1));
        }
        public StylesheetBundleSerializer_Tests()
        {
            bundle = new StylesheetBundle("~")
            {
                Hash = new byte[0],
                Media = "MEDIA",
                Condition = "CONDITION",
                Renderer = new ConstantHtmlRenderer<StylesheetBundle>("", new VirtualDirectoryPrepender("/"))
            };

            WriteToElement();
        }
        public void WhenProcessTwoCssReferencesInSameComment_ThenAssetAddReferenceIsCalledTwice()
        {
            var bundle = new StylesheetBundle("~");
            var css = "/* @reference \"test1.css\"; \n @reference \"test2.css\"; */";
            var asset = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();
            processor.Process(bundle);

            asset.Verify(a => a.AddReference("test1.css", 1));
            asset.Verify(a => a.AddReference("test2.css", 2));
        }
Beispiel #35
0
        public void GivenACompiler_WhenProcessCalled_ThenCompileAssetTransformerAddedToLessAsset()
        {
            var processor = new CompileLess(Mock.Of<ILessCompiler>(), new CassetteSettings());
            var bundle = new StylesheetBundle("~");
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.Path).Returns("test.less");
            bundle.Assets.Add(asset.Object);

            processor.Process(bundle);

            asset.Verify(a => a.AddAssetTransformer(It.Is<IAssetTransformer>(at => at is CompileAsset)));
        }
        public void GivenDebugMode_WhenProcess_ThenBundleRenderIsDebugStylesheetHtmlRenderer()
        {
            var processor = new AssignStylesheetsRenderer();
            var settings  = new CassetteSettings {
                IsDebuggingEnabled = true
            };
            var bundle = new StylesheetBundle("~/test");

            processor.Process(bundle, settings);

            bundle.Renderer.ShouldBeType <DebugStylesheetHtmlRenderer>();
        }
Beispiel #37
0
        public void RenderCallsRenderer()
        {
            var renderer = new Mock<IBundleHtmlRenderer<StylesheetBundle>>();
            var bundle = new StylesheetBundle("~/test")
            {
                Renderer = renderer.Object
            };

            bundle.Render();

            renderer.Verify(r => r.Render(bundle));
        }
	    public void WhenModifiedPipelineProcessesBundle_ThenReferenceInLessAssetIsParsed()
	    {
	        var asset = new Mock<IAsset>();
	        asset.SetupGet(a => a.Path).Returns("~/file.less");
            asset.Setup(a => a.OpenStream()).Returns(() => "// @reference 'other.less';".AsStream());
            var bundle = new StylesheetBundle("~");
	        bundle.Assets.Add(asset.Object);

	        modifiedPipeline.Process(bundle);

            asset.Verify(a => a.AddReference("other.less", 1));
	    }
Beispiel #39
0
        public void WhenProcessSimpleCssReferenceWithSingleQuotes_ThenAssetAddReferenceIsCalled()
        {
            var bundle = new StylesheetBundle("~");
            var css    = "/* @reference 'test.css'; */";
            var asset  = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();

            processor.Process(bundle, new CassetteSettings(""));

            asset.Verify(a => a.AddReference("test.css", 1));
        }
Beispiel #40
0
        public void RenderCallsRenderer()
        {
            var renderer = new Mock <IBundleHtmlRenderer <StylesheetBundle> >();
            var bundle   = new StylesheetBundle("~/test")
            {
                Renderer = renderer.Object
            };

            bundle.Render();

            renderer.Verify(r => r.Render(bundle));
        }
Beispiel #41
0
        public void WhenProcessCssReferenceWithoutTrailingSemicolon_ThenAssetAddReferenceIsCalled()
        {
            var bundle = new StylesheetBundle("~");
            var css    = "/* @reference \"test.css\" */";
            var asset  = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();

            processor.Process(bundle, new CassetteSettings(""));

            asset.Verify(a => a.AddReference("test.css", 1));
        }
        public void GivenProductionMode_WhenProcess_ThenBundleRenderIsStylesheetHtmlRenderer()
        {
            var settings = new CassetteSettings {
                IsDebuggingEnabled = false
            };
            var processor = new AssignStylesheetRenderer(Mock.Of <IUrlGenerator>(), settings);
            var bundle    = new StylesheetBundle("~/test");

            processor.Process(bundle);

            bundle.Renderer.ShouldBeType <StylesheetHtmlRenderer>();
        }
Beispiel #43
0
        public void GivenACompiler_WhenProcessCalled_ThenCompileAssetTransformerNotAddedToCssAsset()
        {
            var processor = new CompileLess(Mock.Of <ICompiler>());
            var bundle    = new StylesheetBundle("~");
            var asset     = new Mock <IAsset>();

            asset.SetupGet(a => a.SourceFile.FullPath).Returns("test.css");
            bundle.Assets.Add(asset.Object);

            processor.Process(bundle, new CassetteSettings());

            asset.Verify(a => a.AddAssetTransformer(It.Is <IAssetTransformer>(at => at is CompileAsset)), Times.Never());
        }
Beispiel #44
0
        public void WhenProcessTwoCssReferencesInDifferentComments_ThenAssetAddReferenceIsCalledTwice()
        {
            var bundle = new StylesheetBundle("~");
            var css    = "/* @reference \"test1.css\"; */\n/* @reference \"test2.css\"; */";
            var asset  = AddCssAsset(bundle, css);

            var processor = new ParseCssReferences();

            processor.Process(bundle, new CassetteSettings(""));

            asset.Verify(a => a.AddReference("test1.css", 1));
            asset.Verify(a => a.AddReference("test2.css", 2));
        }
Beispiel #45
0
        public void WhenModifiedPipelineProcessesBundle_ThenLessAssetHasCompileAssetTransformAdded()
        {
            var asset = new Mock <IAsset>();

            asset.SetupGet(a => a.Path).Returns("~/file.less");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            var bundle = new StylesheetBundle("~");

            bundle.Assets.Add(asset.Object);

            modifiedPipeline.Process(bundle);

            asset.Verify(a => a.AddAssetTransformer(It.Is <IAssetTransformer>(t => t is CompileAsset)));
        }
        public void SpriteImagesAddsSpriteImagesBundleProcessorToEndOfPipeline()
        {
            var pipeline = new Mock<IBundlePipeline<StylesheetBundle>>();
            const int endOfPipeline = 42;
            pipeline.SetupGet(p => p.Count).Returns(endOfPipeline);
            var bundle = new StylesheetBundle("~")
            {
                Pipeline = pipeline.Object
            };

            bundle.SpriteImages();

            pipeline.Verify(p => p.Insert<SpriteImages>(endOfPipeline));
        }
        public StylesheetBundleExtensions_Tests()
        {
            var container = new TinyIoCContainer();
            var settings  = new CassetteSettings();

            container.Register(Mock.Of <IStylesheetMinifier>());
            container.Register(Mock.Of <IUrlGenerator>());
            container.Register(settings);
            pipeline = new StylesheetPipeline(container, settings);
            bundle   = new StylesheetBundle("~")
            {
                Pipeline = pipeline
            };
        }
Beispiel #48
0
        public void WhenModifiedPipelineProcessesBundle_ThenReferenceInLessAssetIsParsed()
        {
            var asset = new Mock <IAsset>();

            asset.SetupGet(a => a.Path).Returns("~/file.less");
            asset.Setup(a => a.OpenStream()).Returns(() => "// @reference 'other.less';".AsStream());
            var bundle = new StylesheetBundle("~");

            bundle.Assets.Add(asset.Object);

            modifiedPipeline.Process(bundle);

            asset.Verify(a => a.AddReference("other.less", 1));
        }
        public void GivenBundleWithMedia_WhenRender_ThenHtmlLinkWithMediaAttributeReturned()
        {
            var bundle = new StylesheetBundle("~/tests")
            {
                Media = "MEDIA"
            };
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateBundleUrl(bundle))
                .Returns("URL");

            var renderer = new StylesheetHtmlRenderer(urlGenerator.Object);
            var html = renderer.Render(bundle);

            html.ShouldEqual("<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\" media=\"MEDIA\"/>");
        }
        public void GivenBundle_WhenRender_ThenHtmlLinkReturned()
        {
            var bundle = new StylesheetBundle("~/tests");
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateBundleUrl(bundle))
                .Returns("URL")
                .Verifiable();

            var renderer = new StylesheetHtmlRenderer(urlGenerator.Object);
            var html = renderer.Render(bundle);

            html.ShouldEqual("<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\"/>");

            urlGenerator.VerifyAll();
        }
        public CombinedStylesheetBundle_Tests()
        {
            settings = new CassetteSettings("1");
            var factory = new StylesheetBundleFactory(settings);

            var bd = new BundleDescriptor();
            bd.AssetFilenames.Add("*");
            inner = factory.CreateBundle("foo", new IFile[]{new InMemoryCssFile()} , bd);

            underTest = new CombinedStylesheetBundle(
                "test bundle",
                new List<StylesheetBundle>(new StylesheetBundle[] { inner }),
                new List<string>(new string[] {"foo"})
            );
        }
Beispiel #52
0
        public void GivenConvertImageUrlsToDataUrisIsFalse_WhenProcessBundle_ThenLessAssetHasNoDataUriTransformAdded()
        {
            var asset = new Mock <IAsset>();

            asset.SetupGet(a => a.Path).Returns("~/file.less");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            var bundle = new StylesheetBundle("~");

            bundle.Assets.Add(asset.Object);

            var pipeline = new StylesheetPipeline(container, settings);

            pipeline.Process(bundle);

            asset.Verify(a => a.AddAssetTransformer(It.Is <IAssetTransformer>(t => t is CssImageToDataUriTransformer)), Times.Never());
        }
        public void GivenBundle_WhenRender_ThenHtmlLinkReturned()
        {
            var bundle       = new StylesheetBundle("~/tests");
            var urlGenerator = new Mock <IUrlGenerator>();

            urlGenerator.Setup(g => g.CreateBundleUrl(bundle))
            .Returns("URL")
            .Verifiable();

            var renderer = new StylesheetHtmlRenderer(urlGenerator.Object);
            var html     = renderer.Render(bundle);

            html.ShouldEqual("<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\"/>");

            urlGenerator.VerifyAll();
        }
Beispiel #54
0
        public void GivenCompileSassIsFalse_WhenProcessBundle_ThenSassAssetHasNoCompileAssetTransformAdded()
        {
            var asset = new Mock <IAsset>();

            asset.SetupGet(a => a.SourceFile.FullPath).Returns("~/file.sass");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            var bundle = new StylesheetBundle("~");

            bundle.Assets.Add(asset.Object);

            var pipeline = new StylesheetPipeline();

            pipeline.Process(bundle, new CassetteSettings(""));

            asset.Verify(a => a.AddAssetTransformer(It.Is <IAssetTransformer>(t => t is CompileAsset)), Times.Never());
        }
Beispiel #55
0
        public void GivenBundleWithMedia_WhenRender_ThenHtmlLinkWithMediaAttributeReturned()
        {
            var bundle = new StylesheetBundle("~/tests")
            {
                Media = "MEDIA"
            };
            var urlGenerator = new Mock <IUrlGenerator>();

            urlGenerator.Setup(g => g.CreateBundleUrl(bundle))
            .Returns("URL");

            var renderer = new StylesheetHtmlRenderer(urlGenerator.Object);
            var html     = renderer.Render(bundle);

            html.ShouldEqual("<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\" media=\"MEDIA\"/>");
        }
Beispiel #56
0
        public void GivenConvertImageUrlsToDataUrisIsTrue_WhenProcessBundle_ThenLessAssetHasDataUriTransformAdded()
        {
            var asset = new Mock <IAsset>();

            asset.SetupGet(a => a.SourceFile.FullPath).Returns("~/file.less");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            var bundle = new StylesheetBundle("~");

            bundle.Assets.Add(asset.Object);

            var pipeline = new StylesheetPipeline {
                ConvertImageUrlsToDataUris = true
            };

            pipeline.Process(bundle, new CassetteSettings(""));

            asset.Verify(a => a.AddAssetTransformer(It.Is <IAssetTransformer>(t => t is CssImageToDataUriTransformer)));
        }
        public void GivenStylesheetBundleWithNotIECondition_WhenRender_ThenHtmlConditionalCommentWrapsLinkButLeavesStylesheetVisibleToAllBrowsers()
        {
            var bundle = new StylesheetBundle("~/test")
            {
                Condition = "(gt IE 9)| !IE"
            };
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateBundleUrl(bundle)).Returns("URL");

            var renderer = new StylesheetHtmlRenderer(urlGenerator.Object);
            var html = renderer.Render(bundle);

            html.ShouldEqual(
                "<!--[if "+ bundle.Condition + "]><!-->" + Environment.NewLine +
                "<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\"/>" + Environment.NewLine +
                "<!-- <![endif]-->"
            );
        }
        public void GivenStylesheetBundleWithCondition_WhenRender_ThenHtmlConditionalCommentWrapsLink()
        {
            var bundle = new StylesheetBundle("~/test")
            {
                Condition = "CONDITION"
            };
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateBundleUrl(bundle)).Returns("URL");

            var renderer = new StylesheetHtmlRenderer(urlGenerator.Object);
            var html = renderer.Render(bundle);

            html.ShouldEqual(
                "<!--[if CONDITION]>" + Environment.NewLine +
                "<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\"/>" + Environment.NewLine +
                "<![endif]-->"
            );
        }
Beispiel #59
0
        public void ProcessAddsExpandCssUrlsAssetTransformerToEachAsset()
        {
            var processor = new ExpandCssUrls();
            var bundle = new StylesheetBundle("~");
            var asset1 = new Mock<IAsset>();
            var asset2 = new Mock<IAsset>();
            bundle.Assets.Add(asset1.Object);
            bundle.Assets.Add(asset2.Object);

            processor.Process(bundle, new CassetteSettings());

            asset1.Verify(a => a.AddAssetTransformer(
                It.Is<IAssetTransformer>(t => t is ExpandCssUrlsAssetTransformer)
            ));
            asset2.Verify(a => a.AddAssetTransformer(
                It.Is<IAssetTransformer>(t => t is ExpandCssUrlsAssetTransformer)
            ));
        }
        public void GivenBundleWithAssets_WhenRender_ThenLinkForEachAssetIsReturned()
        {
            var bundle = new StylesheetBundle("~/test");
            bundle.Assets.Add(new StubAsset());
            bundle.Assets.Add(new StubAsset());

            var urlGenerator = new Mock<IUrlGenerator>();
            var assetUrls = new Queue<string>(new[] { "asset1", "asset2" });
            urlGenerator.Setup(g => g.CreateAssetUrl(It.IsAny<IAsset>(), It.IsAny<bool>()))
                        .Returns(assetUrls.Dequeue);

            var renderer = new DebugStylesheetHtmlRenderer(urlGenerator.Object);
            var html = renderer.Render(bundle);

            html.ShouldEqual(
                "<link href=\"asset1\" type=\"text/css\" rel=\"stylesheet\"/>" +
                Environment.NewLine +
                "<link href=\"asset2\" type=\"text/css\" rel=\"stylesheet\"/>"
            );
        }