public void CanRenderDebugTags()
        {
            debugJavaScriptBundle
            .Add("~/js/test1.js")
            .Add("~/js/test2.js")
            .AsNamed("TestWithDebug", "~/js/output_3.js");

            var tag = debugJavaScriptBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/test1.js\"></script><script type=\"text/javascript\" src=\"js/test2.js\"></script>", tag);
        }
 /// <summary>
 /// Iterates through the files and folders of the given folder and adds any javascript files found.
 /// </summary>
 /// <param name="bundle">The bundle to which javascript files should be added.</param>
 /// <param name="builder">The builder used for everything except the first iteration...</param>
 /// <param name="folder">The folder to search through.</param>
 /// <returns>The modified bundle.</returns>
 private static IJavaScriptBundleBuilder RecursivelyAddFolder(IJavaScriptBundle bundle, IJavaScriptBundleBuilder builder, string folder)
 {
     foreach (var file in Directory.GetFiles(folder).Where(x => Path.GetExtension(x) == ".js"))
         builder = builder == null ? bundle.Add(TranslatePath(file)) : builder.Add(TranslatePath(file));
     foreach (var localFolder in Directory.GetDirectories(folder))
         builder = RecursivelyAddFolder(bundle, builder, localFolder);
     return builder;
 }
Beispiel #3
0
        public void IfPackageFlagIsNotSetThenRenderAsUsual()
        {
            Bundle.PackageJavaScript = false;

            var tag = javaScriptBundle
                      .Add("~/js/test.js")
                      .AsPackageable()
                      .Render("~/js/output_1.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output_1.js?r=8E8C548F4F6300695269DE689B903BA3\"></script>", tag);
            Assert.AreEqual("function product(d,c){return d*c}function sum(d,c){return d+c};", fileWriterFactory.Files[@"C:\js\output_1.js"]);
        }
Beispiel #4
0
        public void IfPackageFlagIsSetButDebugsIsTrueThenRenderAsUsual()
        {
            Bundle.PackageJavaScript = true;
            debugJavaScriptBundle
            .Add("~/js/test1.js")
            .Add("~/js/test2.js")
            .AsPackageable()
            .AsNamed("TestWithDebug", "~/js/output_3.js");

            var tag = debugJavaScriptBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/test1.js\"></script><script type=\"text/javascript\" src=\"js/test2.js\"></script>", tag);
        }
        public void ShouldRenderTheExistingPackagedJavaScriptBundleInsteadOfCreatingANewOne()
        {
            var testFile = "/myfilename_combined_3_234448i484884844848848484484844848.js";

            PackagerTests.delete_all_the_test_files();
            PackagerTests.write_a_test_file_to_the_file_system(testFile);

            //make sure the file reader does not try to load the added files

            var tag = javaScriptBundle
                      .Add("~/js/test.js")
                      .AsPackageable()
                      .Render("~/myfilename_combined_#.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"/myfilename_combined_3_234448i484884844848848484484844848.js\"></script>", tag);
        }
        /// <summary>
        /// Minify the javascript into one file
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="filenames">The filenames.</param>
        /// <param name="outputPathandFilename">The output pathand filename.</param>
        /// <returns></returns>
        public static string Js(this HtmlHelper helper, IEnumerable <string> filenames, string outputPathandFilename)
        {
            IJavaScriptBundle        bundle  = Bundle.JavaScript();
            IJavaScriptBundleBuilder builder = null;

            foreach (string filename in filenames)
            {
                if (builder == null)
                {
                    builder = bundle.Add(filename).WithMinifier(JavaScriptMinifiers.Yui);
                }
                else
                {
                    builder.Add(filename).WithMinifier(JavaScriptMinifiers.Yui);
                }
            }

            return(builder != null ? builder.Render(outputPathandFilename) : string.Empty);
        }
        public void CanRerenderFiles()
        {
            fileReaderFactory.SetFileExists(false);

            javaScriptBundle
            .Add("~/js/test.js")
            .Render("~/js/output_10.js");

            Assert.AreEqual("function product(d,c){return d*c}function sum(d,c){return d+c};", fileWriterFactory.Files[@"C:\js\output_10.js"]);

            fileReaderFactory.SetContents(javaScript2);
            fileReaderFactory.SetFileExists(true);
            fileWriterFactory.Files.Clear();
            javaScriptBundle.ClearCache();

            javaScriptBundle2
            .Add("~/js/test.js")
            .Render("~/js/output_10.js");

            Assert.AreEqual("function sum(d,c){return d+c};", fileWriterFactory.Files[@"C:\js\output_10.js"]);
        }
        public void CanRerenderFiles()
        {
            fileReaderFactory.SetFileExists(false);

            javaScriptBundle
            .Add("~/js/test.js")
            .Render("~/js/output_10.js");

            Assert.AreEqual("function product(a,b){return a*b}function sum(a,b){return a+b}", fileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\js\output_10.js")]);

            fileReaderFactory.SetContents(javaScript2);
            fileReaderFactory.SetFileExists(true);
            fileWriterFactory.Files.Clear();
            javaScriptBundle.ClearTestingCache();

            javaScriptBundle2
            .Add("~/js/test.js")
            .Render("~/js/output_10.js");

            Assert.AreEqual("function sum(a,b){return a+b}", fileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\js\output_10.js")]);
        }
        public void CanBundleJavaScript()
        {
            var tag = javaScriptBundle
                      .Add("~/js/test.js")
                      .Render("~/js/output_1.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output_1.js?r=8E8C548F4F6300695269DE689B903BA3\"></script>", tag);
            Assert.AreEqual("function product(d,c){return d*c}function sum(d,c){return d+c};", fileWriterFactory.Files[@"C:\js\output_1.js"]);
        }
        public void CanBundleJavaScript()
        {
            var tag = javaScriptBundle
                      .Add("~/js/test.js")
                      .Render("~/js/output_1.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output_1.js?r=E36D384488ABCF73BCCE650C627FB74F\"></script>", tag);
            Assert.AreEqual("function product(a,b){return a*b}function sum(a,b){return a+b}", fileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\js\output_1.js")]);
        }