public void SetUp()
        {
            var nonDebugStatusReader = new StubDebugStatusReader(false);

            jsFileWriterFactory = new StubFileWriterFactory();
            jsFileReaderFactory = new StubFileReaderFactory();
            cssFileWriterFactory = new StubFileWriterFactory();
            cssFileReaderFactory = new StubFileReaderFactory();

            jsFileReaderFactory.SetContents(javaScript);
            jsFileReaderFactory.SetPackagedFileNameExists(true);
            jsFileReaderFactory.SetPackagedFileName("/myfilename_combined_3_234448i484884844848848484484844848.js");

            cssFileReaderFactory.SetContents(css);
            cssFileReaderFactory.SetPackagedFileNameExists(true);
            cssFileReaderFactory.SetPackagedFileName("/myfilename_combined_3_234448i484884844848848484484844848.css");

            javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader,
                                                    jsFileWriterFactory,
                                                    jsFileReaderFactory);

            javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader,
                                                     jsFileWriterFactory,
                                                     jsFileReaderFactory);

            cssBundle = new CssBundle(nonDebugStatusReader, cssFileWriterFactory, cssFileReaderFactory);

            Bundle.PackageJavaScript = true;
            Bundle.PackageCss = true;
        }
Beispiel #2
0
        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"]);
        }
Beispiel #3
0
        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 SetUp()
        {
            var nonDebugStatusReader = new StubDebugStatusReader(false);
            var debugStatusReader = new StubDebugStatusReader(true);

            fileWriterFactory = new StubFileWriterFactory();
            fileReaderFactory = new StubFileReaderFactory();
            fileReaderFactory.SetContents(javaScript);
            javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader,
                                                    fileWriterFactory,
                                                    fileReaderFactory);

            javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader,
                                                     fileWriterFactory,
                                                     fileReaderFactory);

            debugJavaScriptBundle = new JavaScriptBundle(debugStatusReader,
                                                         fileWriterFactory,
                                                         fileReaderFactory);

            debugJavaScriptBundle2 = new JavaScriptBundle(debugStatusReader,
                                                          fileWriterFactory,
                                                          fileReaderFactory);
        }
Beispiel #5
0
        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"]);
        }
Beispiel #6
0
        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\" />");
        }
Beispiel #7
0
        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\" />");
        }
Beispiel #8
0
        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);
        }
        public void Setup()
        {
            var nonDebugStatusReader = new StubDebugStatusReader(false);
            var debugStatusReader = new StubDebugStatusReader(true);
            currentDirectoryWrapper = new StubCurrentDirectoryWrapper();
            stubBundleCache = new ApplicationCache();

            var retryableFileOpener = new RetryableFileOpener();
            hasher = new Hasher(retryableFileOpener);

            //fileReaderFactory.SetContents(javaScript);

            javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader,
                                                        fileWriterFactory,
                                                        fileReaderFactory,
                                                        currentDirectoryWrapper,
                                                        hasher,
                                                        stubBundleCache);

            javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader,
                                                        fileWriterFactory,
                                                        fileReaderFactory,
                                                        currentDirectoryWrapper,
                                                        hasher,
                                                        stubBundleCache);

            debugJavaScriptBundle = new JavaScriptBundle(debugStatusReader,
                                                        fileWriterFactory,
                                                        fileReaderFactory,
                                                        currentDirectoryWrapper,
                                                        hasher,
                                                        stubBundleCache);

            debugJavaScriptBundle2 = new JavaScriptBundle(debugStatusReader,
                                                        fileWriterFactory,
                                                        fileReaderFactory,
                                                        currentDirectoryWrapper,
                                                        hasher,
                                                        stubBundleCache);

            outputFileNumber += 1;
            currentOutputFile = outputFileRoot + outputFileNumber + ".js";
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        public void CanBundleCssWithRemote()
        {
            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
                            .AddRemote("/css/first.css", "http://www.someurl.com/css/first.css")
                            .Add("/css/second.css")
                            .Render("/css/output_remote.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"http://www.someurl.com/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/output_remote.css?r=67F81278D746D60E6F711B5A29747388\" />", 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}", mockFileWriterFactory.Files[@"C:\css\output_remote.css"]);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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"]);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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"]);
        }
Beispiel #18
0
        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 Setup()
        {
            var nonDebugStatusReader = new StubDebugStatusReader(false);
            var debugStatusReader = new StubDebugStatusReader(true);
            fileWriterFactory = new StubFileWriterFactory();
            fileReaderFactory = new StubFileReaderFactory();
            currentDirectoryWrapper = new StubCurrentDirectoryWrapper();

            var retryableFileOpener = new RetryableFileOpener();
            hasher = new Hasher(retryableFileOpener);

            fileReaderFactory.SetContents(javaScript);

            javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader,
                                                                                            fileWriterFactory,
                                                                                            fileReaderFactory,
                                                                                            currentDirectoryWrapper,
                                                                                            hasher);

            javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader,
                                                                                            fileWriterFactory,
                                                                                            fileReaderFactory,
                                                                                            currentDirectoryWrapper,
                                                                                            hasher);

            debugJavaScriptBundle = new JavaScriptBundle(debugStatusReader,
                                                                                                    fileWriterFactory,
                                                                                                    fileReaderFactory,
                                                                                                    currentDirectoryWrapper,
                                                                                                    hasher);

            debugJavaScriptBundle2 = new JavaScriptBundle(debugStatusReader,
                                                                                                    fileWriterFactory,
                                                                                                    fileReaderFactory,
                                                                                                    currentDirectoryWrapper,
                                                                                                    hasher);
        }
        public void CanGetOutputUrlForMultipleFilesInReleaseMode()
        {
            var file1 = TestUtilities.PrepareRelativePath("\\js\\test1.js");
            var file2 = TestUtilities.PrepareRelativePath("\\js\\test2.js");
            var subtract = @"function sub (a, b) {
                                return a - b
                             }";
            var divide = @"function div (a, b) {
                                return a / b
                           }";
            fileReaderFactory.SetContentsForFile(file1, javaScript);
            fileReaderFactory.SetContentsForFile(file2, subtract + divide);

            var nonDebugStatusReader = new StubDebugStatusReader(false);

            javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader,
                                                        fileWriterFactory,
                                                        fileReaderFactory,
                                                        currentDirectoryWrapper,
                                                        hasher,
                                                        stubBundleCache);

            var names = javaScriptBundle
                    .Add("~/js/test1.js")
                    .Add("~/js/test2.js")
                    .SquishAndGetUrls("~/js/output_#.js");

            var str = string.Join(",", names.ToArray());
            Assert.AreEqual("js/output_9D7D22AD1BA5843A6E174D152332A1CC.js", str);

            var minifiedScript = "function product(n,t){return n*t}function sum(n,t){return n+t}function sub(n,t){return n-t}function div(n,t){return n/t}";
            var actualScript = fileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output_9D7D22AD1BA5843A6E174D152332A1CC.js")];
            Assert.AreEqual (minifiedScript, actualScript);
        }