protected override void InitializeFileSystem(InMemoryVirtualPathProvider fileSystem) { base.InitializeFileSystem(fileSystem); fileSystem.AddFile("/views/v1.cshtml", View1Html); fileSystem.AddFile("/views/v2.cshtml", View2Html); fileSystem.AddFile("/views/v3.cshtml", View3Html); }
public void OnBeforeEachTest() { RazorFormat.Instance = null; var fileSystem = new InMemoryVirtualPathProvider(new BasicAppHost()); fileSystem.AddFile("/views/TheLayout.cshtml", LayoutHtml); InitializeFileSystem(fileSystem); RazorFormat = new RazorFormat { VirtualPathProvider = fileSystem, PageBaseType = typeof (CustomRazorBasePage<>), EnableLiveReload = false, PrecompilePages = PrecompileEnabled, WaitForPrecompilationOnStartup = WaitForPrecompileEnabled, }.Init(); }
public override List<IVirtualPathProvider> GetVirtualPathProviders() { var existingProviders = base.GetVirtualPathProviders(); var memFs = new InMemoryVirtualPathProvider(this); //Get FileSystem Provider var fs = existingProviders.First(x => x is FileSystemVirtualPathProvider); //Process all .html files: foreach (var file in fs.GetAllMatchingFiles("*.html")) { var contents = Minifiers.HtmlAdvanced.Compress(file.ReadAllText()); memFs.AddFile(file.VirtualPath, contents); } //Process all .css files: foreach (var file in fs.GetAllMatchingFiles("*.css") .Where(file => !file.VirtualPath.EndsWith(".min.css"))) { var contents = Minifiers.Css.Compress(file.ReadAllText()); memFs.AddFile(file.VirtualPath, contents); } //Process all .js files foreach (var file in fs.GetAllMatchingFiles("*.js") .Where(file => !file.VirtualPath.EndsWith(".min.js"))) { try { var js = file.ReadAllText(); var contents = Minifiers.JavaScript.Compress(js); memFs.AddFile(file.VirtualPath, contents); } catch (Exception ex) { //Report any errors in StartUpErrors collection on ?debug=requestinfo base.OnStartupException(new Exception("JSMin Error in {0}: {1}".Fmt(file.VirtualPath, ex.Message))); } } //Give new Memory FS highest priority existingProviders.Insert(0, memFs); return existingProviders; }