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); }
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); }
public void IsVirtualFile() { TestVirtualPathProvider.AddFile(new TestVirtualPathProvider.TestVirtualFile("/file1", "foobar")); Assert.True(VirtualPathHelper.IsVirtualFile("~/file1")); Assert.False(VirtualPathHelper.IsVirtualDirectory("~/file1")); }
public AssetResolverTests() { testVirtualPathProvider = new TestVirtualPathProvider(); bundleManager = new DefaultBundleManager(); bundleManager.VirtualPathProvider = testVirtualPathProvider; resolver = new AssetResolver(bundleManager); }
public void IsVirtualDirectory() { var directory = new TestVirtualPathProvider.TestVirtualDirectory("/dir/"); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/file1.css", "css")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/file1.js", "js")); TestVirtualPathProvider.AddDirectory(directory); Assert.True(VirtualPathHelper.IsVirtualDirectory("~/dir")); Assert.False(VirtualPathHelper.IsVirtualFile("~/dir")); }
public void GetResourcesFiles() { var directory = new TestVirtualPathProvider.TestVirtualDirectory("/dir/"); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/file1.css", "css")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/file1.js", "js")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/file1.map", "map")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/file1.woff", "woff")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/_references.js", "_references")); TestVirtualPathProvider.AddDirectory(directory); Assert.Equal(2, VirtualPathHelper.GetResourcesFiles("~/dir").Count()); }
public InlineStylesTests() { testVirtualPathProvider = new TestVirtualPathProvider(); bundleManager = new DefaultBundleManager(); bundleManager.VirtualPathProvider = testVirtualPathProvider; var context = new HttpContext(new HttpRequest(null, "http://tempuri.org", null), new HttpResponse(null)); //clear cache foreach (System.Collections.DictionaryEntry entry in context.Cache) { context.Cache.Remove((string)entry.Key); } bundleManager.Context = new HttpContextWrapper(context); resolver = new AssetResolver(bundleManager); TagContentBuilder.BundleManager = bundleManager; }
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); }
protected override void Register(Autofac.ContainerBuilder builder) { _descriptor = new ShellDescriptor { }; _testViewEngine = new TestViewEngine(); _testVirtualPathProvider = new TestVirtualPathProvider { TestViewEngine = _testViewEngine }; builder.Register(ctx => _descriptor); builder.RegisterType <StylesheetBindingStrategy>().As <IShapeTableProvider>(); builder.RegisterInstance(_testViewEngine).As <IShapeTemplateViewEngine>(); builder.RegisterInstance(_testVirtualPathProvider).As <IVirtualPathProvider>(); var extensionManager = new Mock <IExtensionManager>(); builder.Register(ctx => extensionManager); builder.Register(ctx => extensionManager.Object); }
protected override void Register(ContainerBuilder builder) { _descriptor = new ShellDescriptor(); _testViewEngine = new TestViewEngine(); _testVirtualPathProvider = new TestVirtualPathProvider(); builder.Register(ctx => _descriptor); builder.RegisterType <StubCacheManager>().As <ICacheManager>(); builder.RegisterType <StubParallelCacheContext>().As <IParallelCacheContext>(); builder.RegisterType <StubVirtualPathMonitor>().As <IVirtualPathMonitor>(); builder.RegisterType <ShapeTemplateBindingStrategy>().As <IShapeTableProvider>(); builder.RegisterType <BasicShapeTemplateHarvester>().As <IShapeTemplateHarvester>(); builder.RegisterInstance(_testViewEngine).As <IShapeTemplateViewEngine>(); builder.RegisterInstance(_testVirtualPathProvider).As <IVirtualPathProvider>(); var extensionManager = new Mock <IExtensionManager>(); builder.Register(ctx => extensionManager); builder.Register(ctx => extensionManager.Object); }
public void CustomVPPWithOneFileNoTransformTest() { //Setup the vpp to contain the files/directories TestVirtualPathProvider vpp = new TestVirtualPathProvider(); var file = new TestVirtualPathProvider.TestVirtualFile("/dir/file", "test"); vpp.AddFile(file); // Setup the bundle Bundle bundle = new Bundle("~/bundles/test"); bundle.Items.VirtualPathProvider = vpp; bundle.Include("~/dir/file"); // Verify the bundle repsonse BundleContext context = SetupContext(bundle, vpp); BundleResponse response = bundle.GetBundleResponse(context); Assert.AreEqual("test\r\n", response.Content); }
public void BundleCustomVPPIncludeDirectoryNestedAllJsTest() { //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 Bundle("~/bundles/test"); bundle.ConcatenationToken = " "; bundle.Items.VirtualPathProvider = vpp; bundle.IncludeDirectory("~/dir/", "*.js", searchSubdirectories: true); // Verify the bundle repsonse BundleContext context = SetupContext(bundle, vpp); BundleResponse response = bundle.GetBundleResponse(context); Assert.AreEqual(@"1 2 a b aa bb c d ", response.Content); }
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); }
public void IncludeWithVersionInDirectoryThrowsTest() { //Setup the vpp to contain the files/directories TestVirtualPathProvider vpp = new TestVirtualPathProvider(); var directory = new TestVirtualPathProvider.TestVirtualDirectory("/jquery1.0.0-pre/"); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/jquery1.0.0-pre/1.js", "alert('1')")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/jquery1.0.0-pre/2.js", "alert('2')")); vpp.AddDirectory(directory); // Setup the bundle ScriptBundle bundle = new ScriptBundle("~/bundles/test"); bundle.Items.VirtualPathProvider = vpp; string error = "Directory does not exist.\r\nParameter name: directoryVirtualPath"; ExceptionHelper.ExpectArgumentException( delegate { bundle.Include("~/jquery{version}/*.js"); }, error); }
public void ScriptBundleCustomVPPIncludeAllJsTest() { //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", "alert('1')")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/2.js", "alert('2')")); vpp.AddDirectory(directory); // Setup the bundle ScriptBundle bundle = new ScriptBundle("~/bundles/test"); bundle.Items.VirtualPathProvider = vpp; bundle.Include("~/dir/*.js"); // Verify the bundle repsonse BundleContext context = SetupContext(bundle, vpp); BundleResponse response = bundle.GetBundleResponse(context); Assert.AreEqual(@"alert(""1"");alert(""2"")", response.Content); }
public void StyleBundleCustomVPPIncludeVersionSelectsTest() { //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/style1.0.css", "correct")); directory.DirectoryFiles.Add(new TestVirtualPathProvider.TestVirtualFile("/dir/style.css", "wrong")); vpp.AddDirectory(directory); // Setup the bundle ScriptBundle bundle = new ScriptBundle("~/bundles/test"); bundle.Items.VirtualPathProvider = vpp; bundle.Include("~/dir/style{version}.css"); // Verify the bundle repsonse BundleContext context = SetupContext(bundle, vpp); BundleResponse response = bundle.GetBundleResponse(context); Assert.AreEqual(@"correct", response.Content); }
public VirtualPathHelperTests() { TestVirtualPathProvider = new TestVirtualPathProvider(); VirtualPathHelper = new VirtualPathHelper(TestVirtualPathProvider); }