예제 #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")]);
        }
예제 #2
0
        public void CanRenderArbitraryStringsInDebugWithoutType()
        {
            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, hrColor, p)
                .WithoutTypeAttribute ()
                .Render ("doesn't matter where...");

            var expectedTag = string.Format ("<style>{0}</style>\n<style>{1}</style>\n", css, string.Format (css2Format, hrColor, p));
            Assert.AreEqual (expectedTag, TestUtilities.NormalizeLineEndings (tag));
        }
예제 #3
0
 public void Setup()
 {
     cssBundleFactory = new CssBundleFactory();
     var retryableFileOpener = new RetryableFileOpener();
     hasher = new Hasher(retryableFileOpener);
 }
예제 #4
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));
        }
예제 #5
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")]);
        }