Пример #1
0
        public void DebugPreferredWithOptimizationsDisabledTest()
        {
            //Setup the vpp to contain the files/directories
            TestVirtualPathProvider vpp = new TestVirtualPathProvider();
            var directory = new TestVirtualPathProvider.TestVirtualDirectory("/");
            var files     = new TestVirtualPathProvider.TestVirtualFile[] {
                new TestVirtualPathProvider.TestVirtualFile("/jquery.js", "jquery"),
                new TestVirtualPathProvider.TestVirtualFile("/jquery.debug.js", "jquery.debug")
            };

            foreach (var file in files)
            {
                directory.DirectoryFiles.Add(file);
                vpp.AddFile(file);
            }
            vpp.AddDirectory(directory);

            // Setup the bundle
            ScriptBundle bundle = new ScriptBundle("~/bundles/test");

            bundle.Items.VirtualPathProvider = vpp;
            bundle.Include("~/jquery.js");

            // Verify the bundle repsonse
            BundleContext context = BundleTest.SetupContext(bundle, vpp);

            context.EnableOptimizations = false;
            BundleResponse response = bundle.GetBundleResponse(context);

            Assert.AreEqual(@"jquery.debug", response.Content);
        }
Пример #2
0
        public void MinJsPreferredWithOptimizationsEnabledTest()
        {
            //Setup the vpp to contain the files/directories
            TestVirtualPathProvider vpp = new TestVirtualPathProvider();
            var directory     = new TestVirtualPathProvider.TestVirtualDirectory("/");
            var jqueryFile    = new TestVirtualPathProvider.TestVirtualFile("/jquery.js", "jquery");
            var jqueryMinFile = new TestVirtualPathProvider.TestVirtualFile("/jquery.min.js", "jquery.min");

            directory.DirectoryFiles.Add(jqueryFile);
            directory.DirectoryFiles.Add(jqueryMinFile);
            vpp.AddDirectory(directory);
            vpp.AddFile(jqueryFile);
            vpp.AddFile(jqueryMinFile);

            // Setup the bundle
            ScriptBundle bundle = new ScriptBundle("~/bundles/test");

            bundle.Items.VirtualPathProvider = vpp;
            bundle.Include("~/jquery.js");

            // Verify the bundle repsonse
            BundleContext context = BundleTest.SetupContext(bundle, vpp);

            context.EnableOptimizations = true;
            BundleResponse response = bundle.GetBundleResponse(context);

            Assert.AreEqual(@"jquery.min", response.Content);
        }
Пример #3
0
        public void DynamicBundleWithCustomVPPSearchSubDirOffTest()
        {
            //Setup the vpp to contain the files/directories
            TestVirtualPathProvider vpp = new TestVirtualPathProvider();
            var directory = new TestVirtualPathProvider.TestVirtualDirectory("/dir/");

            directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/1.js", "1"));
            directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/2.js", "2"));
            vpp.AddDirectory(directory);
            var sub1 = new TestVirtualPathProvider.TestVirtualDirectory("/dir/sub1/");

            sub1.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/sub1/a.js", "a"));
            sub1.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/sub1/b.js", "b"));
            vpp.AddDirectory(sub1);
            directory.SubDirectories.Add(sub1);
            var sub2 = new TestVirtualPathProvider.TestVirtualDirectory("/dir/sub2/");

            sub2.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/sub2/c.js", "c"));
            sub2.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/sub2/d.js", "d"));
            vpp.AddDirectory(sub2);
            directory.SubDirectories.Add(sub2);
            var subSub1 = new TestVirtualPathProvider.TestVirtualDirectory("/dir/sub1/sub/");

            subSub1.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/sub1/sub/aa.js", "aa"));
            subSub1.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/sub1/sub/bb.js", "bb"));
            vpp.AddDirectory(subSub1);
            sub1.SubDirectories.Add(subSub1);

            // Setup the bundle
            Bundle bundle = new DynamicFolderBundle("js", "*.js");

            bundle.ConcatenationToken        = " ";
            bundle.Items.VirtualPathProvider = vpp;

            // Verify the bundle repsonse
            BundleContext context = BundleTest.SetupContext(bundle, vpp);

            context.BundleVirtualPath = "~/dir/js";
            Assert.AreEqual(@"1 2 ", bundle.GetBundleResponse(context).Content);

            context.BundleVirtualPath = "~/dir/sub1/js";
            Assert.AreEqual(@"a b ", bundle.GetBundleResponse(context).Content);

            context.BundleVirtualPath = "~/dir/sub2/js";
            Assert.AreEqual(@"c d ", bundle.GetBundleResponse(context).Content);
        }
Пример #4
0
        public void LessTransformTest()
        {
            //Setup the vpp to contain the files/directories
            TestVirtualPathProvider vpp = new TestVirtualPathProvider();
            var directory = new TestVirtualPathProvider.TestVirtualDirectory("/");

            directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/test.less", @"@color: #111; h2 { color: @color; }"));
            vpp.AddDirectory(directory);

            // Setup the bundle
            Bundle bundle = new Bundle("~/bundles/test", new LessTransform(), new CssMinify());

            bundle.Items.VirtualPathProvider = vpp;
            bundle.Include("~/*.less");

            // Verify the bundle repsonse
            BundleContext  context  = BundleTest.SetupContext(bundle, vpp);
            BundleResponse response = bundle.GetBundleResponse(context);

            Assert.AreEqual(@"h2{color:#111}", response.Content);
        }