Example #1
0
        public void CanBundleArbitraryContentsInRelease()
        {
            var css2Format = "{0}{1}";

            var hrColor = "hr {color:sienna;}";
            var p = "p {margin-left:20px;}";

            var writerFactory = new StubFileWriterFactory();

            var tag = new CSSBundleFactory()
                    .WithDebuggingEnabled(false)
                    .WithFileWriterFactory(writerFactory)
                    .WithHasher(new StubHasher("hashy"))
                    .Create()
                    .AddString(css)
                    .AddString(css2Format, new[] { hrColor, p })
                    .Render("~/output.css");

            var expectedTag = "<link rel=\"stylesheet\" type=\"text/css\" href=\"output.css?r=hashy\" />";
            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));

            var minifiedScript = "li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}hr{color:#a0522d}p{margin-left:20px}";
            Assert.AreEqual(minifiedScript, writerFactory.Files[TestUtilities.PrepareRelativePath("output.css")]);
        }
Example #2
0
 public void Setup()
 {
     cssBundleFactory = new CSSBundleFactory();
     var retryableFileOpener = new RetryableFileOpener();
     hasher = new Hasher(retryableFileOpener);
 }
Example #3
0
        public void CanRenderArbitraryStringsInDebug()
        {
            var css2Format = "{0}{1}";

            var hrColor = "hr {color:sienna;}";
            var p = "p {margin-left:20px;}";

            var tag = new CSSBundleFactory()
                .WithDebuggingEnabled(true)
                .Create()
                .AddString(css)
                .AddString(css2Format, new[] { hrColor, p })
                .Render("doesn't matter where...");

            var expectedTag = string.Format("<style type=\"text/css\">{0}</style>\n<style type=\"text/css\">{1}</style>\n", css, string.Format(css2Format, hrColor, p));
            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
        }
Example #4
0
        public void CanMaintainOrderBetweenArbitraryAndFileAssetsInRelease()
        {
            var file1 = "somefile.css";
            var file2 = "anotherfile.css";

            var arbitraryCss = ".someClass { color:red }";
            var minifiedArbitraryCss = ".someClass{color:red}";

            var readerFactory = new StubFileReaderFactory();
            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file1), css);
            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file2), css2);

            var writerFactory = new StubFileWriterFactory();

            var tag = new CSSBundleFactory()
                .WithFileReaderFactory(readerFactory)
                .WithFileWriterFactory(writerFactory)
                .WithDebuggingEnabled(false)
                .Create()
                .Add(file1)
                .AddString(arbitraryCss)
                .Add(file2)
                .Render("test.css");

            var expectedTag = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"test.css?r=hash\" />");
            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));

            var combined = minifiedCss + minifiedArbitraryCss + minifiedCss2;
            Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"test.css")]);
        }
Example #5
0
 public void Setup()
 {
     stubHasher = new StubHasher("hash");
     cssBundleFactory = new CSSBundleFactory()
         .WithHasher(stubHasher);
 }
Example #6
0
        public void DoesNotRenderDuplicateArbitraryStringsInDebug()
        {
            var tag = new CSSBundleFactory()
                .WithDebuggingEnabled(true)
                .Create()
                .AddString(css)
                .AddString(css)
                .Render("doesn't matter where...");

            var expectedTag = string.Format("<style type=\"text/css\">{0}</style>\n", css);
            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
        }
 public void Setup()
 {
     cssBundleFactory = new CSSBundleFactory();
     hasher = new StubHasher("hash");
 }