public void When_GetFileInfo_and_resource_does_not_exist_then_should_not_get_file_info() { var provider = new EmbeddedFileProvider(this.GetType().Assembly, ""); var fileInfo = provider.GetFileInfo("DoesNotExist.Txt"); fileInfo.ShouldNotBe(null); fileInfo.Exists.ShouldBe(false); }
public void Trigger_ShouldNot_Support_Registering_Callbacks() { var provider = new EmbeddedFileProvider(this.GetType().Assembly, ""); var trigger = provider.Watch("Resources/File.txt"); trigger.ShouldNotBe(null); trigger.ActiveExpirationCallbacks.ShouldBe(false); trigger.IsExpired.ShouldBe(false); }
public void GetDirInfo_with_no_matching_base_namespace() { var provider = new EmbeddedFileProvider(this.GetType().Assembly, "Unknown.Namespace"); var files = provider.GetDirectoryContents(string.Empty); files.ShouldNotBe(null); files.Exists.ShouldBe(true); files.Count().ShouldBe(0); }
public void GetDirectoryContents() { var provider = new EmbeddedFileProvider(this.GetType().Assembly, "Resources"); var files = provider.GetDirectoryContents(""); files.ShouldNotBe(null); files.Count().ShouldBe(2); provider.GetDirectoryContents("file").Exists.ShouldBe(false); provider.GetDirectoryContents("file/").Exists.ShouldBe(false); provider.GetDirectoryContents("file.txt").Exists.ShouldBe(false); provider.GetDirectoryContents("file/txt").Exists.ShouldBe(false); }
public void When_GetFileInfo_and_resources_in_path_then_should_get_file_infos() { var provider = new EmbeddedFileProvider(this.GetType().Assembly, ""); var fileInfo = provider.GetFileInfo("Resources/File.txt"); fileInfo.ShouldNotBe(null); fileInfo.Exists.ShouldBe(true); fileInfo.LastModified.ShouldNotBe(default(DateTimeOffset)); fileInfo.Length.ShouldBeGreaterThan(0); fileInfo.IsDirectory.ShouldBe(false); fileInfo.PhysicalPath.ShouldBe(null); fileInfo.Name.ShouldBe("File.txt"); }
public void Main(string[] args) { Console.WriteLine("Root path : {0}", _appEnvironment.ApplicationBasePath); Console.WriteLine(); var physicalFileProvider = new PhysicalFileProvider(_appEnvironment.ApplicationBasePath); physicalFileProvider.GetInfo(@"c:\github\kichalla\FileProvidersExample\src\FileProvidersExample\Program.cs"); physicalFileProvider.GetInfo("Program.cs"); physicalFileProvider.GetInfo("/Program.cs"); physicalFileProvider.GetInfo(@"\Program.cs"); physicalFileProvider.GetInfo("FileProvidersExample/Program.cs"); physicalFileProvider.GetInfo("/FileProvidersExample/Program.cs"); physicalFileProvider.GetInfo(@"\FileProvidersExample\Program.cs"); Console.WriteLine("***********************************************************"); var embeddedProvider = new EmbeddedFileProvider(this.GetType().GetTypeInfo().Assembly, "FileProvidersExample.EmbeddedResources"); embeddedProvider.GetInfo("Blah.cshtml"); embeddedProvider.GetInfo("/Views/Home/Index.cshtml"); embeddedProvider.GetInfo("Views/Home/Index.cshtml"); embeddedProvider.GetInfo(@"\Views\Home\Index.cshtml"); embeddedProvider.GetInfo(@"Views\Home\Index.cshtml"); }
public void When_GetFileInfo_and_resource_exists_in_root_then_should_get_file_info() { var provider = new EmbeddedFileProvider(this.GetType().Assembly, ""); var expectedFileLength = new FileInfo("File.txt").Length; var fileInfo = provider.GetFileInfo("File.txt"); fileInfo.ShouldNotBe(null); fileInfo.Exists.ShouldBe(true); fileInfo.LastModified.ShouldNotBe(default(DateTimeOffset)); fileInfo.Length.ShouldBe(expectedFileLength); fileInfo.IsDirectory.ShouldBe(false); fileInfo.PhysicalPath.ShouldBe(null); fileInfo.Name.ShouldBe("File.txt"); //Passing in a leading slash fileInfo = provider.GetFileInfo("/File.txt"); fileInfo.ShouldNotBe(null); fileInfo.Exists.ShouldBe(true); fileInfo.LastModified.ShouldNotBe(default(DateTimeOffset)); fileInfo.Length.ShouldBe(expectedFileLength); fileInfo.IsDirectory.ShouldBe(false); fileInfo.PhysicalPath.ShouldBe(null); fileInfo.Name.ShouldBe("File.txt"); }
//[InlineData(@"TestFiles\EmbeddedSourceFile.txt")] public void DisplaysSourceCodeLines_ForRelativeEmbeddedPaths(string relativePath) { // Arrange var provider = new EmbeddedFileProvider( GetType().GetTypeInfo().Assembly, baseNamespace: $"{typeof(DeveloperExceptionPageMiddlewareTest).GetTypeInfo().Assembly.GetName().Name}.Resources"); // Act var middleware = GetErrorPageMiddleware(provider); var stackFrame = middleware.GetStackFrame("func1", relativePath, lineNumber: 10); // Assert // Lines 4-16 (inclusive) is the code block Assert.Equal(4, stackFrame.PreContextLine); Assert.Equal(GetCodeLines(4, 9), stackFrame.PreContextCode); Assert.Equal(GetCodeLines(10, 10), stackFrame.ContextCode); Assert.Equal(GetCodeLines(11, 16), stackFrame.PostContextCode); }
public SafeEmbeddedFileProvider(Assembly assembly) { _baseNamespace = ""; _inner = new EmbeddedFileProvider(assembly); }