Пример #1
0
        public void BuildBundleRequiresApplicationPathTest()
        {
            OptimizationSettings settings = new OptimizationSettings()
            {
                BundleManifestPath = "bundle.config"
            };

            ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(() => { Optimizer.BuildBundle("~/bundles/js", settings); }, "settings.ApplicationPath");
        }
Пример #2
0
        public void BuildBundleRequiresBundlePathTest()
        {
            OptimizationSettings settings = new OptimizationSettings()
            {
                ApplicationPath    = TestContext.DeploymentDirectory,
                BundleManifestPath = "bundle.config"
            };

            ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(() => { Optimizer.BuildBundle("", settings); }, "bundlePath");
        }
Пример #3
0
        public void OptimizerReturnsNullWhenNoBundleRegistered()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath    = TestContext.DeploymentDirectory,
                BundleManifestPath = "bundle.config"
            };
            BundleResponse response = Optimizer.BuildBundle("~/bundles/none", config);

            Assert.IsNull(response);
        }
        public void ShouldBuildTemplateBundle()
        {
            BundleTable.EnableOptimizations = true;

            var response = Optimizer.BuildBundle("~/templates", new OptimizationSettings
            {
                ApplicationPath   = Path.GetFullPath("../../../fixtures"),
                BundleSetupMethod = SetupBundles
            });

            Assert.Equal(File.ReadAllText("../../../expected/compiled3.js"), response.Content);
        }
Пример #5
0
        public void OptimizerStyleBundleUsingBundleConfig()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath    = TestContext.DeploymentDirectory,
                BundleManifestPath = "bundle.config"
            };
            BundleResponse response = Optimizer.BuildBundle("~/bundles/css", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("Css2{color:blue}Css3{color:blue}Css1{color:blue}", response.Content);
            Assert.AreEqual(CssMinify.CssContentType, response.ContentType);
        }
Пример #6
0
        public void OptimizerScriptBundleUsingBundleConfig()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath    = TestContext.DeploymentDirectory,
                BundleManifestPath = "bundle.config"
            };
            BundleResponse response = Optimizer.BuildBundle("~/bundles/js", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("alert(\"first\");alert(\"second\")", response.Content);
            Assert.AreEqual(JsMinify.JsContentType, response.ContentType);
        }
Пример #7
0
        public void OptimizerDynamicFolderBundleBadDirectory()
        {
            BundleCollection bundles = new BundleCollection();

            bundles.Add(new DynamicFolderBundle("js", "*.js", new JsMinify()));
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath = TestContext.DeploymentDirectory,
                BundleTable     = bundles
            };

            ExceptionHelper.ExpectException <InvalidOperationException>(() => { Optimizer.BuildBundle("~/foo/js", config); }, "Directory does not exist.");
        }
Пример #8
0
        public void OptimizerUsingSetupMethodWithMissingFileThrows()
        {
            BundleCollection bundles = new BundleCollection();

            bundles.Add(new ScriptBundle("~/zzzz").Include("~/totallyfake.notexist"));
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath = TestContext.DeploymentDirectory,
                BundleTable     = bundles
            };

            ExceptionHelper.ExpectException <FileNotFoundException>(() => { Optimizer.BuildBundle("~/zzzz", config); });
        }
Пример #9
0
        public void OptimizerUppercaseItemTransformTest()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    bundles.Add(new ScriptBundle("~/bundles/upper").Include("~/scripts/first.js", new UppercaseTransform()));
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/bundles/upper", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("ALERT(\"FIRST\")", response.Content);
            Assert.AreEqual(JsMinify.JsContentType, response.ContentType);
        }
Пример #10
0
        public void OptimizerWithWildcardMissUsingSetupMethodOnly()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    bundles.Add(new ScriptBundle("~/bundles/js").Include("~/scripts/none-*"));
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/bundles/js", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("", response.Content);
            Assert.AreEqual(JsMinify.JsContentType, response.ContentType);
        }
Пример #11
0
        public void OptimizerCssInTwoDirectoriesTest()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    bundles.Add(new StyleBundle("~/bundles/css").Include("~/Styles/image.css", "~/Styles/nested/image2.css"));
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/bundles/css", config);

            Assert.IsNotNull(response);
            Assert.AreEqual(".image{background:url(images/ui.png)}.image2{background:url(images/ui2.png)}", response.Content);
            Assert.AreEqual(CssMinify.CssContentType, response.ContentType);
        }
Пример #12
0
        public void OptimizerDynamicBundleTest()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    bundles.Add(new DynamicFolderBundle("js", "*.js", new JsMinify()));
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/scripts/js", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("alert(\"first\");alert(\"second\")", response.Content);
            Assert.AreEqual(JsMinify.JsContentType, response.ContentType);
        }
Пример #13
0
        public void OptimizerBundleItemsAddWithBadPathThrowsFileNotFoundExceptionTest()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    var bundle     = new ScriptBundle("~/bundles/bogus");
                    var bundleItem = new BundleItem("~/totallybogus");
                    bundle.Items.Add(bundleItem);
                    bundles.Add(bundle);
                }
            };

            ExceptionHelper.ExpectException <FileNotFoundException>(() => {
                BundleResponse response = Optimizer.BuildBundle("~/bundles/bogus", config);
            });
        }
Пример #14
0
        public void OptimizerCssUrlRewriteWithWildcardTest()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    bundles.Add(new StyleBundle("~/bundles/css")
                                .Include("~/Styles/image.css", new CssRewriteUrlTransform(), new UppercaseTransform())
                                .Include("~/Styles/nested/*.css", new CssRewriteUrlTransform()));
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/bundles/css", config);

            Assert.IsNotNull(response);
            // Note: Minification of the bundle lower cases the url
            Assert.AreEqual(".IMAGE{BACKGROUND:url(/STYLES/IMAGES/UI.PNG)}.image2{background:url(/Styles/nested/images/ui2.png)}", response.Content);
            Assert.AreEqual(CssMinify.CssContentType, response.ContentType);
        }
Пример #15
0
        public void OptimizerUsingSetupMethodOnly()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    bundles.Add(new ScriptBundle("~/bundles/js").Include("~/scripts/first.js"));
                    bundles.Add(new StyleBundle("~/bundles/css").Include("~/styles/1.css"));
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/bundles/js", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("alert(\"first\")", response.Content);
            Assert.AreEqual(JsMinify.JsContentType, response.ContentType);

            response = Optimizer.BuildBundle("~/bundles/css", config);
            Assert.IsNotNull(response);
            Assert.AreEqual("Css1{color:blue}", response.Content);
            Assert.AreEqual(CssMinify.CssContentType, response.ContentType);
        }
Пример #16
0
        public void OptimizerUppercaseOnlyFirstItemTransformTest()
        {
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath   = TestContext.DeploymentDirectory,
                BundleSetupMethod = (bundles) => {
                    var bundle     = new ScriptBundle("~/bundles/upper");
                    var bundleItem = new BundleItem("~/scripts/first.js");
                    bundleItem.Transforms.Add(new UppercaseTransform());
                    bundle.Items.Add(bundleItem);
                    bundleItem = new BundleItem("~/scripts/second.js");
                    bundle.Items.Add(bundleItem);
                    bundles.Add(bundle);
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/bundles/upper", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("ALERT(\"FIRST\");alert(\"second\")", response.Content);
            Assert.AreEqual(JsMinify.JsContentType, response.ContentType);
        }
Пример #17
0
        private BundledSequence BundleSequence(IList <HtmlNode> sequence, string documentPath, FileUnitOfWork unitOfWork)
        {
            var parentPath = Path.GetDirectoryName(documentPath);
            var settings   = new OptimizationSettings {
                BundleTable     = new BundleCollection(),
                ApplicationPath = parentPath
            };

            var paths  = sequence.Select(r => this.handler.GetPath(r)).ToArray();
            var bundle = new Bundle("~/stub")
                         .Include(paths.Select(p => "~/" + p).ToArray());

            bundle.Transforms.Add(this.handler.Transform);
            settings.BundleTable.Add(bundle);

            var response = Optimizer.BuildBundle(bundle.Path, settings);

            foreach (var path in paths)
            {
                unitOfWork.RequestDelete(Path.Combine(parentPath, path));
            }

            return(new BundledSequence(sequence, response.Content));
        }
Пример #18
0
        public void OptimizerSetupMethodOverridesConfig()
        {
            // Override config bundles to be empty
            OptimizationSettings config = new OptimizationSettings()
            {
                ApplicationPath    = TestContext.DeploymentDirectory,
                BundleManifestPath = "bundle.config",
                BundleSetupMethod  = (bundles) => {
                    bundles.Add(new ScriptBundle("~/bundles/js"));
                    bundles.Add(new StyleBundle("~/bundles/css"));
                }
            };

            BundleResponse response = Optimizer.BuildBundle("~/bundles/js", config);

            Assert.IsNotNull(response);
            Assert.AreEqual("", response.Content);
            Assert.AreEqual(JsMinify.JsContentType, response.ContentType);

            response = Optimizer.BuildBundle("~/bundles/css", config);
            Assert.IsNotNull(response);
            Assert.AreEqual("", response.Content);
            Assert.AreEqual(CssMinify.CssContentType, response.ContentType);
        }