public void AbsolutePathNotAllowed() { var provider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "sub")); var applicationBase = Directory.GetCurrentDirectory(); var file1 = Path.Combine(applicationBase, "File.txt"); var info = provider.GetFileInfo(file1); Assert.NotNull(info); Assert.False(info.Exists); var file2 = Path.Combine(applicationBase, "sub", "File2.txt"); info = provider.GetFileInfo(file2); Assert.NotNull(info); Assert.False(info.Exists); var directory1 = Path.Combine(applicationBase, "sub"); var directoryContents = provider.GetDirectoryContents(directory1); Assert.NotNull(info); Assert.False(info.Exists); var directory2 = Path.Combine(applicationBase, "Does_Not_Exists"); directoryContents = provider.GetDirectoryContents(directory2); Assert.NotNull(info); Assert.False(info.Exists); }
public void GetDirectoryContents_FromRootPath_ForEmptyDirectoryName() { var provider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "sub")); var info = provider.GetDirectoryContents(string.Empty); Assert.NotNull(info); Assert.True(info.Exists); var firstDirectory = info.Where(f => f.IsDirectory).Where(f => f.Exists).FirstOrDefault(); Assert.Throws <InvalidOperationException>(() => firstDirectory.CreateReadStream()); var fileInfo = info.Where(f => f.Name == "File2.txt").FirstOrDefault(); Assert.NotNull(fileInfo); Assert.True(fileInfo.Exists); }
public void AbsolutePathNotAllowed() { var serviceProvider = CallContextServiceLocator.Locator.ServiceProvider; var appEnvironment = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment)); var provider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, "sub")); var applicationBase = appEnvironment.ApplicationBasePath; var file1 = Path.Combine(applicationBase, "File.txt"); var info = provider.GetFileInfo(file1); info.ShouldNotBe(null); info.Exists.ShouldBe(false); var file2 = Path.Combine(applicationBase, "sub", "File2.txt"); info = provider.GetFileInfo(file2); info.ShouldNotBe(null); info.Exists.ShouldBe(false); var directory1 = Path.Combine(applicationBase, "sub"); var directoryContents = provider.GetDirectoryContents(directory1); info.ShouldNotBe(null); info.Exists.ShouldBe(false); var directory2 = Path.Combine(applicationBase, "Does_Not_Exists"); directoryContents = provider.GetDirectoryContents(directory2); info.ShouldNotBe(null); info.Exists.ShouldBe(false); }
public void GetDirectoryContents_FromRootPath_ForEmptyDirectoryName() { var provider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, "sub")); var info = provider.GetDirectoryContents(string.Empty); info.ShouldNotBe(null); info.Exists.ShouldBe(true); var firstDirectory = info.Where(f => f.IsDirectory).Where(f => f.Exists).FirstOrDefault(); Should.Throw<InvalidOperationException>(() => firstDirectory.CreateReadStream()); var fileInfo = info.Where(f => f.Name == "File2.txt").FirstOrDefault(); fileInfo.ShouldNotBe(null); fileInfo.Exists.ShouldBe(true); }
public void GetDirectoryContentsDoesNotReturnFileInfoForFileNameStartingWithPeriod() { using (var root = new DisposableFileSystem()) { var directoryName = Guid.NewGuid().ToString(); var directoryPath = Path.Combine(root.RootPath, directoryName); Directory.CreateDirectory(directoryPath); var fileName = "." + Guid.NewGuid().ToString(); var filePath = Path.Combine(directoryPath, fileName); File.Create(filePath); using (var provider = new PhysicalFileProvider(root.RootPath)) { var contents = provider.GetDirectoryContents(directoryName); Assert.Empty(contents); } } }
public void GetDirectoryContents_FromRootPath_ForEmptyDirectoryName() { var provider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "sub")); var info = provider.GetDirectoryContents(string.Empty); Assert.NotNull(info); Assert.True(info.Exists); var firstDirectory = info.Where(f => f.IsDirectory).Where(f => f.Exists).FirstOrDefault(); Assert.Throws<InvalidOperationException>(() => firstDirectory.CreateReadStream()); var fileInfo = info.Where(f => f.Name == "File2.txt").FirstOrDefault(); Assert.NotNull(fileInfo); Assert.True(fileInfo.Exists); }
public void GetDirectoryContentsDoesNotReturnFileInfoForSystemFile() { using (var root = new DisposableFileSystem()) { var directoryName = Guid.NewGuid().ToString(); var directoryPath = Path.Combine(root.RootPath, directoryName); Directory.CreateDirectory(directoryPath); var fileName = Guid.NewGuid().ToString(); var filePath = Path.Combine(directoryPath, fileName); File.Create(filePath); var fileInfo = new FileInfo(filePath); File.SetAttributes(filePath, fileInfo.Attributes | FileAttributes.System); using (var provider = new PhysicalFileProvider(root.RootPath)) { var contents = provider.GetDirectoryContents(directoryName); Assert.Empty(contents); } } }
public void GetDirectoryContentsReturnsRootDirectoryContentsForEmptyPath() { using (var root = new DisposableFileSystem()) { File.Create(Path.Combine(root.RootPath, "File" + Guid.NewGuid().ToString())); Directory.CreateDirectory(Path.Combine(root.RootPath, "Dir" + Guid.NewGuid().ToString())); using (var provider = new PhysicalFileProvider(root.RootPath)) { var contents = provider.GetDirectoryContents(string.Empty); Assert.Collection(contents.OrderBy(c => c.Name), item => Assert.IsType<PhysicalDirectoryInfo>(item), item => Assert.IsType<PhysicalFileInfo>(item)); } } }
public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForNonExistingDirectory() { using (var provider = new PhysicalFileProvider(Path.GetTempPath())) { var contents = provider.GetDirectoryContents(Guid.NewGuid().ToString()); Assert.IsType(typeof(NotFoundDirectoryContents), contents); } }
public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForNullPath() { using (var provider = new PhysicalFileProvider(Path.GetTempPath())) { var contents = provider.GetDirectoryContents(null); Assert.IsType(typeof(NotFoundDirectoryContents), contents); } }
public void InvalidPath_DoesNotThrowGeneric_GetDirectoryContents(string path) { using (var provider = new PhysicalFileProvider(Directory.GetCurrentDirectory())) { var info = provider.GetDirectoryContents(path); Assert.NotNull(info); Assert.IsType<NotFoundDirectoryContents>(info); } }