public void FilePathPrefixFormatted() { var fileProvider = new Mock<IFileSystem>(); var provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); Assert.AreEqual(provider.PathPrefix, "/media/"); }
public void FilePathPrefixFormatted() { var fileProvider = new Mock <IFileSystem>(); var provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); Assert.AreEqual(provider.PathPrefix, "/media/"); }
public void should_return_false_when_file_name_contains_invalid_characters() { var pathProvider = new FileSystemVirtualPathProvider(); pathProvider.RegisterContentDirectory("/yada"); pathProvider.FileExists("/yada\""); }
public void FilePathShouldBeExecuted() { var fileProvider = new Mock<IFileSystem>(); var provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); var result = provider.GetFile("~/media/1001/media.jpg"); Assert.IsNotNull(result); }
public void FilePathShouldBeNotIgnored() { var fileProvider = new Mock<IFileSystem>(); var provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); var result = provider.GetFile("~/styles/main.css"); Assert.IsNull(result); }
public void FilePathShouldBeExecuted() { var fileProvider = new Mock <IFileSystem>(); var provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); var result = provider.GetFile("~/media/1001/media.jpg"); Assert.IsNotNull(result); }
public void FilePathPrefixFormatted() { // Arrange/Act Mock <IFileSystem> fileProvider = new Mock <IFileSystem>(); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider(Constants.DefaultMediaRoute, new Lazy <IFileSystem>(() => fileProvider.Object)); // Assert Assert.AreEqual(provider.PathPrefix, "/media/"); }
public void FilePathShouldBeNotIgnored() { var fileProvider = new Mock <IFileSystem>(); var provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); var result = provider.GetFile("~/styles/main.css"); Assert.IsNull(result); }
public BasicAppHost() { this.Container = new Container(); this.PreRequestFilters = new List <Action <IHttpRequest, IHttpResponse> >(); this.RequestFilters = new List <Action <IHttpRequest, IHttpResponse, object> >(); this.ResponseFilters = new List <Action <IHttpRequest, IHttpResponse, object> >(); this.ViewEngines = new List <IViewEngine>(); this.CatchAllHandlers = new List <HttpHandlerResolverDelegate>(); VirtualPathProvider = new FileSystemVirtualPathProvider(this, "~".MapServerPath()); }
public void ProviderShouldCallFileSystemFileExists() { var stream = new MemoryStream(); var fileProvider = new Mock<IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1001/media.jpg")).Returns(stream); var provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); provider.FileExists("~/media/1001/media.jpg"); fileProvider.Verify(p => p.FileExists("1001/media.jpg"), Times.Once); }
public void FilePathShouldBeExecuted() { // Arrange Mock <IFileSystem> fileProvider = new Mock <IFileSystem>(); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); // Act VirtualFile result = provider.GetFile("~/media/1010/media.jpg"); // Assert Assert.IsNotNull(result); }
public void FilePathShouldBeExecuted() { // Arrange Mock<IFileSystem> fileProvider = new Mock<IFileSystem>(); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); // Act VirtualFile result = provider.GetFile("~/media/1010/media.jpg"); // Assert Assert.IsNotNull(result); }
// Pre user config public static void ConfigureHost(IAppHost appHost, string serviceName, ServiceManager serviceManager) { AppHost = appHost; EndpointHostConfig.Instance.ServiceName = serviceName; EndpointHostConfig.Instance.ServiceManager = serviceManager; var config = EndpointHostConfig.Instance; Config = config; // avoid cross-dependency on Config setter VirtualPathProvider = new FileSystemVirtualPathProvider(AppHost, Config.WebHostPhysicalPath); }
public void Update_Razor_and_Markdown_pages_at_runtime() { var fs = new FileSystemVirtualPathProvider(appHost, "~/../RazorRockstars.WebHost".MapHostAbsolutePath()); var kurtRazor = fs.GetFile("stars/dead/cobain/default.cshtml"); s3.WriteFile(kurtRazor.VirtualPath, "[UPDATED RAZOR] " + kurtRazor.ReadAllText()); var kurtMarkdown = fs.GetFile("stars/dead/cobain/Content.md"); s3.WriteFile(kurtMarkdown.VirtualPath, "[UPDATED MARKDOWN] " + kurtMarkdown.ReadAllText()); }
public void ProviderShouldCallFileSystemFileExists() { var stream = new MemoryStream(); var fileProvider = new Mock <IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1001/media.jpg")).Returns(stream); var provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); provider.FileExists("~/media/1001/media.jpg"); fileProvider.Verify(p => p.FileExists("1001/media.jpg"), Times.Once); }
public override void OnConfigLoad() { if (app != null) { //Initialize VFS var env = app.ApplicationServices.GetService <IHostingEnvironment>(); Config.WebHostPhysicalPath = env.ContentRootPath; //Set VirtualFiles to point to ContentRootPath (Project Folder) VirtualFiles = new FileSystemVirtualPathProvider(this, env.ContentRootPath); } }
public void ProviderShouldCallFileSystemOpen() { var stream = new MemoryStream(); var fileProvider = new Mock<IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1001/media.jpg")).Returns(stream); var provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); var result = provider.GetFile("~/media/1001/media.jpg"); var streamResult = result.Open(); Assert.AreEqual(stream, streamResult); fileProvider.Verify(p => p.OpenFile("1001/media.jpg"), Times.Once); }
public HtmlBodyMail() { VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), Path.Combine("~".MapHostAbsolutePath(), TemplateDir)); RazorFormat.Instance = null; Razor = new RazorFormat { VirtualPathProvider = VirtualPathProvider, EnableLiveReload = false, PrecompilePages = true, WaitForPrecompilationOnStartup = true, //PageBaseType = typeof(ViewPage<>), }.Init(); }
public void ProviderShouldCallFileSystemOpen() { var stream = new MemoryStream(); var fileProvider = new Mock <IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1001/media.jpg")).Returns(stream); var provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); var result = provider.GetFile("~/media/1001/media.jpg"); var streamResult = result.Open(); Assert.AreEqual(stream, streamResult); fileProvider.Verify(p => p.OpenFile("1001/media.jpg"), Times.Once); }
public void ProviderShouldCallFileSystemFileExists() { using (MemoryStream stream = new MemoryStream()) { // Arrange Mock <IFileSystem> fileProvider = new Mock <IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1010/media.jpg")).Returns(stream); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); // Act provider.FileExists("~/media/1010/media.jpg"); // Assert fileProvider.Verify(p => p.FileExists("1010/media.jpg"), Times.Once); } }
// Pre user config public static void ConfigureHost(IAppHost appHost, string serviceName, ServiceManager serviceManager) { AppHost = appHost; EndpointHostConfig.Instance.ServiceName = serviceName; EndpointHostConfig.Instance.ServiceManager = serviceManager; var config = EndpointHostConfig.Instance; Config = config; // avoid cross-dependency on Config setter VirtualPathProvider = new FileSystemVirtualPathProvider(AppHost, Config.WebHostPhysicalPath); Config.DebugMode = appHost.GetType().Assembly.IsDebugBuild(); if (Config.DebugMode) { Plugins.Add(new RequestInfoFeature()); } }
public void ProviderShouldCallFileSystemOpenFile() { using (MemoryStream stream = new MemoryStream()) { // Arrange Mock <IFileSystem> fileProvider = new Mock <IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1010/media.jpg")).Returns(stream); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider("media", new Lazy <IFileSystem>(() => fileProvider.Object)); // Act VirtualFile result = provider.GetFile("~/media/1010/media.jpg"); // Assert using (Stream streamResult = result.Open()) { Assert.AreEqual(stream, streamResult); fileProvider.Verify(p => p.OpenFile("1010/media.jpg"), Times.Once); } } }
public void Copy_Razor_files_to_AWS_Bucket() { var fs = new FileSystemVirtualPathProvider(appHost, "~/../RazorRockstars.WebHost".MapHostAbsolutePath()); var skipDirs = new[] { "bin", "obj" }; var matchingFileTypes = new[] { "cshtml", "md", "css", "js", "png", "jpg" }; var replaceHtmlTokens = new Dictionary <string, string> { { "title-bg.png", "title-bg-aws.png" }, //Title Background { "https://gist.github.com/3617557.js", "https://gist.github.com/mythz/396dbf54ce6079cc8b2d.js" }, //AppHost.cs { "https://gist.github.com/3616766.js", "https://gist.github.com/mythz/ca524426715191b8059d.js" }, //S3 RockstarsService.cs { "RazorRockstars.WebHost/RockstarsService.cs", "RazorRockstars.S3/RockstarsService.cs" }, //S3 RockstarsService.cs { "http://github.com/ServiceStackApps/RazorRockstars/", "https://github.com/ServiceStackApps/RazorRockstars/tree/master/src/RazorRockstars.S3" } //Link to GitHub project }; foreach (var file in fs.GetAllFiles()) { if (skipDirs.Any(x => file.VirtualPath.StartsWith(x))) { continue; } if (!matchingFileTypes.Contains(file.Extension)) { continue; } if (file.Extension == "cshtml") { var html = file.ReadAllText(); replaceHtmlTokens.Each(x => html = html.Replace(x.Key, x.Value)); s3.WriteFile(file.VirtualPath, html); } else { s3.WriteFile(file); } } }
public void ProviderShouldCallFileSystemFileExists() { using (MemoryStream stream = new MemoryStream()) { // Arrange Mock<IFileSystem> fileProvider = new Mock<IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1010/media.jpg")).Returns(stream); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); // Act provider.FileExists("~/media/1010/media.jpg"); // Assert fileProvider.Verify(p => p.FileExists("1010/media.jpg"), Times.Once); } }
private void ImportData() { var dir = new FileSystemVirtualPathProvider(this, BaseDir ?? Config.WebHostPhysicalPath); var fileSettings = dir.GetFile("app.settings"); var appSettings = fileSettings != null ? new DictionarySettings(fileSettings.ReadAllText().ParseKeyValueText(delimiter: " ")) : new DictionarySettings(); var fileServerLabels = dir.GetFile("server.labels"); var serverLabels = fileServerLabels != null ? fileServerLabels.ReadAllText().ParseKeyValueText(delimiter: " ") : null; var fileTestLabels = dir.GetFile("test.labels"); var testLabels = fileTestLabels != null ? fileTestLabels.ReadAllText().ParseKeyValueText(delimiter: " ") : null; using (var admin = Resolve <AdminServices>()) { var db = admin.Db; db.DropAndCreateTable <TestPlan>(); db.DropAndCreateTable <TestRun>(); db.DropAndCreateTable <TestResult>(); const int planId = 1; admin.CreateTestPlan(new TestPlan { Id = planId, Name = appSettings.Get("TestPlanName", "Benchmarks"), ServerLabels = serverLabels, TestLabels = testLabels, }); var testRun = admin.CreateTestRun(planId); var files = UploadFile != null ? dir.GetAllMatchingFiles(UploadFile) : dir.GetAllMatchingFiles("*.txt") .Concat(dir.GetAllMatchingFiles("*.zip")); admin.Request = new BasicRequest { Files = files.Map(x => new HttpFile { ContentLength = x.Length, ContentType = MimeTypes.GetMimeType(x.Name), FileName = x.Name, InputStream = x.OpenRead(), } as IHttpFile).ToArray() }; if (admin.Request.Files.Length > 0) { admin.Post(new UploadTestResults { TestPlanId = 1, TestRunId = testRun.Id, CreateNewTestRuns = true, }); } } }
public void ProviderShouldCallFileSystemOpenFile() { using (MemoryStream stream = new MemoryStream()) { // Arrange Mock<IFileSystem> fileProvider = new Mock<IFileSystem>(); fileProvider.Setup(p => p.OpenFile("1010/media.jpg")).Returns(stream); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object)); // Act VirtualFile result = provider.GetFile("~/media/1010/media.jpg"); // Assert using (Stream streamResult = result.Open()) { Assert.AreEqual(stream, streamResult); fileProvider.Verify(p => p.OpenFile("1010/media.jpg"), Times.Once); } } }