Beispiel #1
0
        public void GivenACompiler_WhenProcessCalled_ThenCompileAssetTransformerNotAddedToCssAsset()
        {
            var processor = new CompileLess(Mock.Of<ICompiler>());
            var module = new StylesheetModule("~");
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFilename).Returns("test.css");
            module.Assets.Add(asset.Object);

            processor.Process(module, Mock.Of<ICassetteApplication>());

            asset.Verify(a => a.AddAssetTransformer(It.Is<IAssetTransformer>(at => at is CompileAsset)), Times.Never());
        }
        public void GivenModule_WhenRender_ThenHtmlLinkReturned()
        {
            var module = new StylesheetModule("~/tests");
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateModuleUrl(module))
                        .Returns("URL")
                        .Verifiable();

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

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

            urlGenerator.VerifyAll();
        }
        public void GivenModuleWithMedia_WhenRender_ThenHtmlLinkWithMediaAttributeReturned()
        {
            var module = new StylesheetModule("~/tests")
            {
                Media = "MEDIA"
            };
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateModuleUrl(module))
                        .Returns("URL");

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

            html.ShouldEqual("<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\" media=\"MEDIA\"/>");
        }
Beispiel #4
0
        public void ProcessAddsExpandCssUrlsAssetTransformerToEachAsset()
        {
            var processor = new ExpandCssUrls();
            var module = new StylesheetModule("~");
            var asset1 = new Mock<IAsset>();
            var asset2 = new Mock<IAsset>();
            module.Assets.Add(asset1.Object);
            module.Assets.Add(asset2.Object);

            processor.Process(module, Mock.Of<ICassetteApplication>());

            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 GivenModuleWithAssetsThatIsTransformed_WhenRender_ThenLinkHtmlHasTransformUrlReturned()
        {
            var module = new StylesheetModule("~/test");
            var asset = new Mock<IAsset>();
            asset.Setup(a => a.HasTransformers)
                 .Returns(true);
            module.Assets.Add(asset.Object);

            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateAssetCompileUrl(module, It.IsAny<IAsset>()))
                        .Returns("URL");

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

            html.ShouldEqual(
                "<link href=\"URL\" type=\"text/css\" rel=\"stylesheet\"/>"
            );
        }
        public void GivenModuleWithAssets_WhenRender_ThenLinkForEachAssetIsReturned()
        {
            var module = new StylesheetModule("~/test");
            module.Assets.Add(Mock.Of<IAsset>());
            module.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(module).ToHtmlString();

            html.ShouldEqual(
                "<link href=\"asset1\" type=\"text/css\" rel=\"stylesheet\"/>" +
                Environment.NewLine +
                "<link href=\"asset2\" type=\"text/css\" rel=\"stylesheet\"/>"
            );
        }
        public StylesheetPipeline_Process_TestBase()
        {
            application = new Mock<ICassetteApplication>();
            module = new StylesheetModule("~");
            asset1 = new Mock<IAsset>();
            asset2 = new Mock<IAsset>();
            module.Assets.Add(asset1.Object);
            module.Assets.Add(asset2.Object);

            asset1.SetupGet(a => a.SourceFilename)
                  .Returns("~/asset1.css");
            asset1.Setup(a => a.OpenStream())
                  .Returns(() => "/* @reference \"asset2.css\"; */".AsStream());
            asset2.SetupGet(a => a.SourceFilename)
                  .Returns("~/asset2.css");
            asset2.Setup(a => a.OpenStream())
                  .Returns(() => "p { color: White; }".AsStream());
            asset1.SetupGet(a => a.References)
                  .Returns(new[] { new AssetReference("~/asset2.css", asset1.Object, -1, AssetReferenceType.SameModule) });
        }
Beispiel #8
0
 StylesheetModule StubStylesheetModule(string path)
 {
     var module = new StylesheetModule(path);
     var asset = new Mock<IAsset>();
     asset.SetupGet(a => a.Hash).Returns(new byte[] { 1, 2, 3 });
     module.Assets.Add(asset.Object);
     return module;
 }