public void ProcessReturnsCssWithDataUrls() { const string css = "#myclass{background:url(\"../Images/orderedList0.png\") no-repeat;}#myclass2{background:url('../Images/orderedList0.png') no-repeat;}#myclass3{background:url(../Images/orderedList0.png) no-repeat;}"; var fileProvider = Substitute.For <IFileProvider>(); fileProvider.Exists(Arg.Any <string>()).Returns(true); fileProvider.ReadAllText(Arg.Any <string>()).Returns(css); fileProvider.ReadAllBytes(Arg.Any <string>()).Returns(System.Text.Encoding.ASCII.GetBytes(@"test")); var httpContext = Substitute.For <HttpContextBase>(); var context = new BundleContext(httpContext, new BundleCollection(), string.Empty); var files = new List <FileInfo> { new FileInfo(@"css\test.css") }; var response = new BundleResponse(css, files); var transform = new CssDataUriTransform(fileProvider); transform.Process(context, response); Assert.AreEqual("text/css", response.ContentType); Assert.AreEqual("#myclass{background:url(\"data:image/png;base64,dGVzdA==\") no-repeat;}#myclass2{background:url('data:image/png;base64,dGVzdA==') no-repeat;}#myclass3{background:url(data:image/png;base64,dGVzdA==) no-repeat;}", response.Content); }
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( "~/Scripts/jquery-ui-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate*")); // Use the development version of Modernizr to develop with and learn from. Then, when you're // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( "~/Scripts/modernizr-*")); // limits converted files to a max of 20kb var cssDataUriTransformer = new CssDataUriTransform(new DefaultFileProvider(), new FileSizeExclusion(new DefaultFileProvider(), 20000)); var contentStyleBundle = new StyleBundle("~/Content/css").Include("~/Content/site.css"); contentStyleBundle.Transforms.Add(cssDataUriTransformer); contentStyleBundle.Transforms.Add(new CssMinify()); bundles.Add(contentStyleBundle); var baseStyleBundle = new StyleBundle("~/Content/themes/base/css").Include( "~/Content/themes/base/jquery.ui.core.css", "~/Content/themes/base/jquery.ui.resizable.css", "~/Content/themes/base/jquery.ui.selectable.css", "~/Content/themes/base/jquery.ui.accordion.css", "~/Content/themes/base/jquery.ui.autocomplete.css", "~/Content/themes/base/jquery.ui.button.css", "~/Content/themes/base/jquery.ui.dialog.css", "~/Content/themes/base/jquery.ui.slider.css", "~/Content/themes/base/jquery.ui.tabs.css", "~/Content/themes/base/jquery.ui.datepicker.css", "~/Content/themes/base/jquery.ui.progressbar.css", "~/Content/themes/base/jquery.ui.theme.css"); baseStyleBundle.Transforms.Add(cssDataUriTransformer); baseStyleBundle.Transforms.Add(new CssMinify()); bundles.Add(baseStyleBundle); // Enable the following to force transformations - should only do this during development //BundleTable.EnableOptimizations = true; }
public void ProcessReturnsCssWithDataUrlsExcludingSchemaReferencedImages() { const string css = "#myclass{background:url(\"../Images/orderedList0.png\") no-repeat;}#myclass2{background:url(\"http://local/Images/orderedList0.png\") no-repeat;}"; var fileProvider = Substitute.For<IFileProvider>(); fileProvider.Exists(Arg.Any<string>()).Returns(true); fileProvider.ReadAllText(Arg.Any<string>()).Returns(css); fileProvider.ReadAllBytes(Arg.Any<string>()).Returns(System.Text.Encoding.ASCII.GetBytes(@"test")); var httpContext = Substitute.For<HttpContextBase>(); var context = new BundleContext(httpContext, new BundleCollection(), string.Empty); var files = new List<FileInfo> { new FileInfo(@"css\test.css") }; var response = new BundleResponse(css, files); var transform = new CssDataUriTransform(fileProvider); transform.Process(context, response); Assert.AreEqual("text/css", response.ContentType); Assert.AreEqual("#myclass{background:url(\"data:image/png;base64,dGVzdA==\") no-repeat;}#myclass2{background:url(\"http://local/Images/orderedList0.png\") no-repeat;}", response.Content); }