コード例 #1
0
 public void Setup()
 {
     javaScriptBundleFactory = new JavaScriptBundleFactory()
         .WithDebuggingEnabled(false)
         .WithHasher(new StubHasher("hash"))
         .WithContents(javaScript);
     //javaScriptBundleFactory.FileReaderFactory.SetContents(javaScript);
 }
コード例 #2
0
        public void CanBundleArbitraryContentsInRelease()
        {
            var js2Format = "{0}{1}";

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

            var writerFactory = new StubFileWriterFactory();

            var tag = new JavaScriptBundleFactory()
                    .WithDebuggingEnabled(false)
                    .WithFileWriterFactory(writerFactory)
                    .WithHasher(new StubHasher("hashy"))
                    .Create()
                    .AddString(javaScript)
                    .AddString(js2Format, new[] { subtract, divide })
                    .Render("~/output.js");

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

            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};";
            Assert.AreEqual(minifiedScript, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
        }
コード例 #3
0
        public void CanRenderArbitraryStringsInDebugWithoutType()
        {
            var js2Format = "{0}{1}";

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

            var tag = new JavaScriptBundleFactory()
                .WithDebuggingEnabled(true)
                .Create()
                .AddString(javaScript)
                .AddString(js2Format, new[] { subtract, divide })
                .WithoutTypeAttribute()
                .Render("doesn't matter where...");

            var expectedTag = string.Format("<script>{0}</script>\n<script>{1}</script>\n", javaScript, string.Format(js2Format, subtract, divide));
            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
        }
コード例 #4
0
        public void CanMaintainOrderBetweenArbitraryAndFileAssetsInRelease()
        {
            var file1 = "somefile.js";
            var file2 = "anotherfile.js";

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

            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(false)
                .Create()
                .Add(file1)
                .AddString(subtract)
                .Add(file2)
                .Render("test.js");

            var expectedTag = string.Format("<script type=\"text/javascript\" src=\"test.js?r=hash\"></script>");
            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));

            var combined = minifiedJavaScript + minifiedSubtract + minifiedJavaScript2;
            Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"test.js")]);
        }
コード例 #5
0
        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));
        }
コード例 #6
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(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));
            }
        }
コード例 #7
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(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")]);
            }
        }
コード例 #8
0
        public void CanBundleDirectoryContentsInDebug_Writes_And_Ignores_Preprocessed_Debug_Files()
        {
            var path = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.script.js");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file1.script.js.squishit.debug.js");
            var content = "some stuffs";

            var preprocessor = new StubScriptPreprocessor();

            using(new ScriptPreprocessorScope<StubScriptPreprocessor>(preprocessor))
            using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 })))
            {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, content);

                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.script.js.squishit.debug.js\"></script>\n", path);
                Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
                Assert.AreEqual(content, preprocessor.CalledWith);
                Assert.AreEqual(1, writerFactory.Files.Count);
                Assert.AreEqual("scripty", writerFactory.Files[file1 + ".squishit.debug.js"]);
            }
        }
コード例 #9
0
        public void DoesNotRenderDuplicateArbitraryStringsInDebug()
        {
            var tag = new JavaScriptBundleFactory()
                .WithDebuggingEnabled(true)
                .Create()
                .AddString(javaScript)
                .AddString(javaScript)
                .Render("doesn't matter where...");

            var expectedTag = string.Format("<script type=\"text/javascript\">{0}</script>\n", javaScript);
            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
        }
コード例 #10
0
ファイル: HoganTests.cs プロジェクト: paulyoder/SquishIt
 public void Setup()
 {
     javaScriptBundleFactory = new JavaScriptBundleFactory();
 }
コード例 #11
0
        public void Includes_Semicolon_And_Newline_Between_Scripts()
        {
            var writerFactory = new StubFileWriterFactory();

            var tag = new JavaScriptBundleFactory()
                    .WithDebuggingEnabled(false)
                    .WithFileWriterFactory(writerFactory)
                    .WithHasher(new StubHasher("hashy"))
                    .Create()
                    .AddString("first")
                    .AddString("second")
                    .Render("~/output.js");

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

            var minifiedScript = "first;\nsecond;\n";
            Assert.AreEqual(minifiedScript, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
        }
コード例 #12
0
 public void Setup()
 {
     javaScriptBundleFactory = new JavaScriptBundleFactory()
         .WithDebuggingEnabled(false);
     javaScriptBundleFactory.FileReaderFactory.SetContents(javaScript);
     var retryableFileOpener = new RetryableFileOpener();
     hasher = new Hasher(retryableFileOpener);
 }
コード例 #13
0
 public void Setup()
 {
     javaScriptBundleFactory = new JavaScriptBundleFactory();
     var retryableFileOpener = new RetryableFileOpener();
     hasher = new Hasher(retryableFileOpener);
 }
コード例 #14
0
 public void Setup()
 {
     javaScriptBundleFactory = new JavaScriptBundleFactory();
     hasher = new StubHasher("hash");
 }