Esempio n. 1
0
        public void CanBundleDirectoryContentsInDebug()
        {
            var path = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PreparePath (Environment.CurrentDirectory + "\\" + path + "\\file1.js");
            var file2 = TestUtilities.PreparePath(Environment.CurrentDirectory + "\\" + path + "\\file2.js");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 })))
            {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
                frf.SetContentsForFile(file2, javaScript);

                var writerFactory = new StubFileWriterFactory();

                var tag = new JavaScriptBundleFactory()
                        .WithDebuggingEnabled(true)
                        .WithFileReaderFactory(frf)
                        .WithFileWriterFactory(writerFactory)
                        .WithHasher(new StubHasher("hashy"))
                        .Create()
                        .Add(path)
                        .Render("~/output.js");

                var expectedTag = string.Format("<script type=\"text/javascript\" src=\"{0}/file1.js\"></script>\n<script type=\"text/javascript\" src=\"{0}/file2.js\"></script>\n", path);
                Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
            }
        }
Esempio n. 2
0
        public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, css2);
                frf.SetContentsForFile(file2, css);

                var writerFactory = new StubFileWriterFactory();

                var tag = cssBundleFactory.WithDebuggingEnabled(false)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Add(file1)
                          .Render("~/output.css");

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

                var combined = "li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}";
                Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.css")]);
            }
        }
        public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.js");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.js");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
                frf.SetContentsForFile(file2, javaScript);

                var writerFactory = new StubFileWriterFactory();

                var tag = new JavaScriptBundleFactory()
                          .WithDebuggingEnabled(false)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Add(file1)
                          .Render("~/output.js");

                var expectedTag = "<script type=\"text/javascript\" src=\"output.js?r=hashy\"></script>";
                Assert.AreEqual(expectedTag, tag);

                var combined = "function replace(n,t){return n+t}function product(n,t){return n*t}function sum(n,t){return n+t}";
                Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
            }
        }
Esempio n. 4
0
        public void CanBundleDirectoryContentsInDebug_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, css2);
                frf.SetContentsForFile(file2, css);

                var writerFactory = new StubFileWriterFactory();

                var tag = cssBundleFactory.WithDebuggingEnabled(true)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Render("~/output.css");

                var expectedTag = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"/{0}/file1.css\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/{0}/file2.css\" />\n", path);
                Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
            }
        }
        public void CanMaintainOrderBetweenArbitraryAndFileAssetsInDebug()
        {
            var file1 = "somefile.js";
            var file2 = "anotherfile.js";

            var subtract = "function sub(a,b){return a-b}";

            var readerFactory = new StubFileReaderFactory();

            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file1), javaScript);
            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file2), javaScript2);

            var writerFactory = new StubFileWriterFactory();

            var tag = new JavaScriptBundleFactory()
                      .WithFileReaderFactory(readerFactory)
                      .WithFileWriterFactory(writerFactory)
                      .WithDebuggingEnabled(true)
                      .Create()
                      .Add(file1)
                      .AddString(subtract)
                      .Add(file2)
                      .Render("test.js");

            var expectedTag = string.Format("<script type=\"text/javascript\" src=\"somefile.js\"></script>\n<script type=\"text/javascript\">{0}</script>\n<script type=\"text/javascript\" src=\"anotherfile.js\"></script>\n"
                                            , subtract);

            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
        }
        public void CanBundleDirectoryContentsInDebug_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PreparePath(Environment.CurrentDirectory + "\\" + path + "\\file1.js");
            var file2 = TestUtilities.PreparePath(Environment.CurrentDirectory + "\\" + path + "\\file2.js");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
                frf.SetContentsForFile(file2, javaScript);

                var writerFactory = new StubFileWriterFactory();

                var tag = new JavaScriptBundleFactory()
                          .WithDebuggingEnabled(true)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Add(file1)
                          .Render("~/output.js");

                var expectedTag = string.Format("<script type=\"text/javascript\" src=\"/{0}/file1.js\"></script>\n<script type=\"text/javascript\" src=\"/{0}/file2.js\"></script>\n", path);
                Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
            }
        }
Esempio n. 7
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"]);
        }
Esempio n. 8
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 CanBundleJsVaryingOutputBaseHrefRendersIndependentUrl()
        {
            var firstPath  = "first.js";
            var secondPath = "second.js";

            fileReaderFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(firstPath), javaScript);
            fileReaderFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(secondPath), javaScript2);

            string tag = javaScriptBundle
                         .Add(firstPath)
                         .Add(secondPath)
                         .WithOutputBaseHref("http://subdomain.domain.com")
                         .Render("/js/output.js");

            string tagNoBaseHref = javaScriptBundle2
                                   .Add(firstPath)
                                   .Add(secondPath)
                                   .Render("/js/output.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"http://subdomain.domain.com/js/output.js?r=A01134C134801A6DEC25510924C1EEA4\"></script>", tag);
            Assert.AreEqual("<script type=\"text/javascript\" src=\"/js/output.js?r=A01134C134801A6DEC25510924C1EEA4\"></script>", tagNoBaseHref);
        }
Esempio n. 10
0
        public void CanBundleJavascriptInRelease(Type preprocessorType)
        {
            var preprocessor = Activator.CreateInstance(preprocessorType) as IPreprocessor;

            const string template         = "<h1>{{message}}</h1>";
            var          templateFileName = "test.hogan.html";
            var          resolver         = StubResolver.ForFile(TestUtilities.PrepareRelativePath(templateFileName));

            var readerFactory = new StubFileReaderFactory();

            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(templateFileName), template);

            var writerFactory = new StubFileWriterFactory();

            string tag;

            using (new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver))
            {
                tag = javaScriptBundleFactory
                      .WithFileReaderFactory(readerFactory)
                      .WithFileWriterFactory(writerFactory)
                      .WithDebuggingEnabled(false)
                      .Create()
                      .WithPreprocessor(preprocessor)
                      .Add("~/" + templateFileName)
                      .Render("~/template.js");
            }

            //are minifier's optimizations here OK?
            var compiled =
                @"var JST=JST||{};JST.test=new Hogan.Template(function(n,t,i){var r=this;return r.b(i=i||""""),r.b(""<h1>""),r.b(r.v(r.f(""message"",n,t,0))),r.b(""<\/h1>""),r.fl()},""" + template.Replace("/", @"\/") + "\",Hogan,{});";

            Assert.AreEqual(1, writerFactory.Files.Count);
            var expectedTag = "<script type=\"text/javascript\" src=\"template.js?r=hash\"></script>";

            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));

            var actual = writerFactory.Files[TestUtilities.PrepareRelativePath("template.js")];

            Assert.AreEqual(compiled + "\n", actual);
        }
Esempio n. 11
0
        public void CanBundleJavascriptInDebug(Type preprocessorType)
        {
            var preprocessor = Activator.CreateInstance(preprocessorType) as IPreprocessor;

            const string template         = "<h1>{{message}}</h1>";
            var          templateFileName = "test.hogan.html";
            var          resolver         = StubResolver.ForFile(TestUtilities.PrepareRelativePath(templateFileName));

            var readerFactory = new StubFileReaderFactory();

            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(templateFileName), template);

            var writerFactory = new StubFileWriterFactory();

            string tag;

            using (new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver))
            {
                tag = javaScriptBundleFactory
                      .WithFileReaderFactory(readerFactory)
                      .WithFileWriterFactory(writerFactory)
                      .WithDebuggingEnabled(true)
                      .Create()
                      .WithPreprocessor(preprocessor)
                      .Add("~/" + templateFileName)
                      .Render("~/template.js");
            }

            var sb = new StringBuilder();

            sb.AppendLine(@"var JST = JST || {};");
            sb.AppendLine(@"JST['test'] = new Hogan.Template(function(c,p,i){var _=this;_.b(i=i||"""");_.b(""<h1>"");_.b(_.v(_.f(""message"",c,p,0)));_.b(""</h1>"");return _.fl();;},""" + template + "\",Hogan,{});");
            var compiled = sb.ToString();

            Assert.AreEqual(1, writerFactory.Files.Count);
            var expectedTag = "<script type=\"text/javascript\" src=\"test.hogan.html.squishit.debug.js\"></script>\n";

            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));

            Assert.AreEqual(compiled, writerFactory.Files[TestUtilities.PrepareRelativePath("test.hogan.html.squishit.debug.js")]);
        }
Esempio n. 12
0
        public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
        {
            var path = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, css2);
                frf.SetContentsForFile(file2, css);

                var writerFactory = new StubFileWriterFactory();

                var tag = cssBundleFactory.WithDebuggingEnabled(false)
                        .WithFileReaderFactory(frf)
                        .WithFileWriterFactory(writerFactory)
                        .WithHasher(new StubHasher("hashy"))
                        .Create()
                        .Add(path)
                        .Add(file1)
                        .Render("~/output.css");

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

                var combined = "li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}";
                Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.css")]);
            }
        }
Esempio n. 13
0
        public void CanBundleDirectoryContentsInDebug_Ignores_Duplicates()
        {
            var path = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, css2);
                frf.SetContentsForFile(file2, css);

                var writerFactory = new StubFileWriterFactory();

                var tag = cssBundleFactory.WithDebuggingEnabled(true)
                        .WithFileReaderFactory(frf)
                        .WithFileWriterFactory(writerFactory)
                        .WithHasher(new StubHasher("hashy"))
                        .Create()
                        .Add(path)
                        .Render("~/output.css");

                var expectedTag = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/file1.css\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/file2.css\" />\n", path);
                Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
            }
        }
Esempio n. 14
0
        public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
        {
            var path = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.js");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.js");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
                frf.SetContentsForFile(file2, javaScript);

                var writerFactory = new StubFileWriterFactory();

                var tag = new JavaScriptBundleFactory()
                        .WithDebuggingEnabled(false)
                        .WithFileReaderFactory(frf)
                        .WithFileWriterFactory(writerFactory)
                        .WithHasher(new StubHasher("hashy"))
                        .Create()
                        .Add(path)
                        .Add(file1)
                        .Render("~/output.js");

                var expectedTag = "<script type=\"text/javascript\" src=\"output.js?r=hashy\"></script>";
                Assert.AreEqual(expectedTag, tag);

                var combined = "function replace(n,t){return n+t}function product(n,t){return n*t}function sum(n,t){return n+t}";
                Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
            }
        }
Esempio n. 15
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"]);
        }
Esempio n. 16
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"]);
        }