public void CanBundleCss() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .Render("/css/output.css"); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output.css?r=C33D1225DED9D889876CEE87754EE305\" />", tag); Assert.AreEqual(1, mockFileWriterFactory.Files.Count); Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", mockFileWriterFactory.Files[@"C:\css\output.css"]); }
public void CanMarkCssBundleAsPackageable() { ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, cssMockFileReaderFactory); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .AsPackageable() .Render("/css/render_differently_if_packaged_#.css"); }
public void CanBundleCssWithCompressorAttribute() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .WithCompressor(CssCompressors.YuiCompressor) .Render("/css/css_with_compressor_output.css"); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/css_with_compressor_output.css?r=AE4C10DB94E5420AD54BD0A0BE9F02C2\" />", tag); Assert.AreEqual(1, mockFileWriterFactory.Files.Count); Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}", mockFileWriterFactory.Files[@"C:\css\css_with_compressor_output.css"]); }
public void CanRerenderFiles() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); mockFileReaderFactory.SetFileExists(false); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); cssBundle.ClearCache(); cssBundle .Add("/css/first.css") .Render("~/css/can_rerender_files.css"); Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", mockFileWriterFactory.Files[@"C:\css\can_rerender_files.css"]); mockFileReaderFactory.SetContents(css2); mockFileReaderFactory.SetFileExists(true); mockFileWriterFactory.Files.Clear(); cssBundle.ClearCache(); ICssBundle cssBundle2 = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); cssBundle2 .Add("/css/first.css") .Render("~/css/can_rerender_files.css"); Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}", mockFileWriterFactory.Files[@"C:\css\can_rerender_files.css"]); }
public void CanRenderDebugTagsTwice() { var mockDebugStatusReader = new StubDebugStatusReader(true); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle1 = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); ICssBundle cssBundle2 = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag1 = cssBundle1 .Add("/css/first.css") .Add("/css/second.css") .Render("/css/output.css"); string tag2 = cssBundle2 .Add("/css/first.css") .Add("/css/second.css") .Render("/css/output.css"); Assert.AreEqual(tag1, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/second.css\" />"); Assert.AreEqual(tag2, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/second.css\" />"); }
public void CanRenderDebugTagsWithMediaAttribute() { var mockDebugStatusReader = new StubDebugStatusReader(true); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .WithMedia("screen") .Render("/css/output.css"); Assert.AreEqual(tag, "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/second.css\" />"); }
public void CanRenderCssFileWithImportStatementUppercase() { string importCss = @" @IMPORT URL(/css/other.css); #header { color: #4D926F; }"; var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(importCss); mockFileReaderFactory.SetContentsForFile(@"C:\css\other.css", "#footer{color:#ffffff}"); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("/css/first.css") .ProcessImports() .Render("/css/processed_import_uppercase.css"); Assert.AreEqual("#footer{color:#fff}#header{color:#4d926f}", mockFileWriterFactory.Files[@"C:\css\processed_import_uppercase.css"]); }
public void CanRenderCssFileWithUnprocessedImportStatement() { string importCss = @" @import url(""/css/other.css""); #header { color: #4D926F; }"; var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(importCss); mockFileReaderFactory.SetContentsForFile(@"C:\css\other.css", "#footer{color:#ffffff}"); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); cssBundle .Add("/css/first.css") .Render("/css/unprocessed_import.css"); Assert.AreEqual(@"@import url(""/css/other.css"");#header{color:#4d926f}", mockFileWriterFactory.Files[@"C:\css\unprocessed_import.css"]); }
public void CanCreateNamedBundleWithDebug() { var mockDebugStatusReader = new StubDebugStatusReader(true); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); cssBundle .Add("~/css/temp1.css") .Add("~/css/temp2.css") .AsNamed("TestWithDebug", "~/css/output.css"); string tag = cssBundle.RenderNamed("TestWithDebug"); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/temp1.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"css/temp2.css\" />", tag); }
public void CanCreateNamedBundleWithMediaAttribute() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); cssBundle .Add("~/css/temp.css") .WithMedia("screen") .AsNamed("TestWithMedia", "~/css/output.css"); string tag = cssBundle.RenderNamed("TestWithMedia"); Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", mockFileWriterFactory.Files[@"C:\css\output.css"]); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"css/output.css?r=67F81278D746D60E6F711B5A29747388\" />", tag); }
public void CanBundleCssWithQueryStringParameter() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .Render("/css/output_querystring.css?v=1"); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output_querystring.css?v=1&r=C33D1225DED9D889876CEE87754EE305\" />", tag); }
public void CanBundleCssWithNullCompressorAttribute() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("/css/first.css") .Add("/css/second.css") .WithCompressor(CssCompressors.NullCompressor) .Render("/css/css_with_null_compressor_output.css"); Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/css_with_null_compressor_output.css?r=9650CBE3E753DF5F9146A2AF738A8272\" />", tag); Assert.AreEqual(1, mockFileWriterFactory.Files.Count); Assert.AreEqual(css + css, mockFileWriterFactory.Files[@"C:\css\css_with_null_compressor_output.css"]); }
public void CanBundleCssWithLessWithLessDotCssFileExtension() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(cssLess); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("~/css/test.less.css") .Render("~/css/output_less_dot_css.css"); string contents = mockFileWriterFactory.Files[@"C:\css\output_less_dot_css.css"]; Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output_less_dot_css.css?r=15D3D9555DEFACE69D6AB9E7FD972638\" />", tag); Assert.AreEqual("#header{color:#4d926f}h2{color:#4d926f}", contents); }
public void CanBundleCssWithLessAndPathRewrites() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); string css = @"@brand_color: #4D926F; #header { color: @brand_color; background-image: url(../image/mygif.gif); } "; mockFileReaderFactory.SetContents(css); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("~/css/something/test.less") .Render("~/css/output_less_with_rewrites.css"); string contents = mockFileWriterFactory.Files[@"C:\css\output_less_with_rewrites.css"]; Assert.AreEqual("#header{color:#4d926f;background-image:url(image/mygif.gif)}", contents); }
public void CanBundleCssWithLess() { var mockDebugStatusReader = new StubDebugStatusReader(false); var mockFileWriterFactory = new StubFileWriterFactory(); var mockFileReaderFactory = new StubFileReaderFactory(); mockFileReaderFactory.SetContents(cssLess); ICssBundle cssBundle = new CssBundle(mockDebugStatusReader, mockFileWriterFactory, mockFileReaderFactory); string tag = cssBundle .Add("~/css/test.less") .Render("~/css/output.css"); string contents = mockFileWriterFactory.Files[@"C:\css\output.css"]; Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=B6B2E7F6525BFBE6045FC275CD84C03F\" />", tag); Assert.AreEqual("#header,h2{color:#4d926f}", contents); }