public void GetFilePath_Resolves_RelativePaths(string path, string relativePathToFile) { // Arrange var fileSystem = new PhysicalFileSystem(Path.GetFullPath("./TestFiles")); var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile)); var filePathResult = new FilePathResult(path, "text/plain", fileSystem); // Act var result = filePathResult.ResolveFilePath(fileSystem); // Assert Assert.Equal(expectedPath, result); }
public void GetFilePath_FailsToResolve_InvalidVirtualPaths(string path, string relativePathToFile) { // Arrange var fileSystem = new PhysicalFileSystem(Path.GetFullPath("./TestFiles")); var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile)); var filePathResult = new FilePathResult(path, "text/plain", fileSystem); // Act var ex = Assert.Throws <FileNotFoundException>(() => filePathResult.ResolveFilePath(fileSystem)); // Assert Assert.Equal("Could not find file: " + path, ex.Message); Assert.Equal(path, ex.FileName); }
public void GetFilePath_ThrowsFileNotFound_IfItCanNotFindTheFile(string path) { // Arrange // Point the IFileSystem root to a different subfolder var fileSystem = new PhysicalFileSystem(Path.GetFullPath("./Utils")); var filePathResult = new FilePathResult(path, "text/plain", fileSystem); var expectedFileName = path.TrimStart('~').Replace('\\', '/'); var expectedMessage = "Could not find file: " + expectedFileName; // Act var ex = Assert.Throws <FileNotFoundException>(() => filePathResult.ResolveFilePath(fileSystem)); // Assert Assert.Equal(expectedMessage, ex.Message); Assert.Equal(expectedFileName, ex.FileName); }
public void GetFilePath_Resolves_RelativePaths(string path, string relativePathToFile) { // Arrange var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile)); var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./TestFiles")); var filePathResult = new FilePathResult(path, "text/plain") { FileProvider = fileProvider, }; // Act var resolveFilePathResult = filePathResult.ResolveFilePath(fileProvider); // Assert Assert.NotNull(resolveFilePathResult); Assert.NotNull(resolveFilePathResult.FileInfo); Assert.Equal(expectedPath, resolveFilePathResult.PhysicalFilePath); }
public void GetFilePath_ThrowsFileNotFound_IfItCanNotFindTheFile(string path) { // Arrange // Point the IFileProvider root to a different subfolder var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Utils")); var filePathResult = new FilePathResult(path, "text/plain") { FileProvider = fileProvider, }; var expectedFileName = path.TrimStart('~').Replace('\\', '/'); var expectedMessage = "Could not find file: " + expectedFileName; // Act var ex = Assert.Throws<FileNotFoundException>(() => filePathResult.ResolveFilePath(fileProvider)); // Assert Assert.Equal(expectedMessage, ex.Message); Assert.Equal(expectedFileName, ex.FileName); }
public void GetFilePath_FailsToResolve_InvalidVirtualPaths(string path, string relativePathToFile) { // Arrange var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./TestFiles")); var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile)); var filePathResult = new FilePathResult(path, "text/plain") { FileProvider = fileProvider, }; // Act var ex = Assert.Throws<FileNotFoundException>(() => filePathResult.ResolveFilePath(fileProvider)); // Assert Assert.Equal("Could not find file: " + path, ex.Message); Assert.Equal(path, ex.FileName); }