public void TestEnumerate() { var fs = new PhysicalFileSystem(); var path = fs.ConvertPathFromInternal(SystemPath); var files = fs.EnumerateFiles(path).Select(p => fs.ConvertPathToInternal(p)).ToList(); var expectedfiles = Directory.EnumerateFiles(SystemPath).ToList(); Assert.Equal(expectedfiles, files); var dirs = fs.EnumerateDirectories(path / "../../..").Select(p => fs.ConvertPathToInternal(p)).ToList(); var expecteddirs = Directory.EnumerateDirectories(Path.GetFullPath(Path.Combine(SystemPath, "..\\..\\.."))).ToList(); Assert.Equal(expecteddirs, dirs); var paths = fs.EnumeratePaths(path / "../..").Select(p => fs.ConvertPathToInternal(p)).ToList(); var expectedPaths = Directory.EnumerateFileSystemEntries(Path.GetFullPath(Path.Combine(SystemPath, "..\\.."))).ToList(); Assert.Equal(expectedPaths, paths); }
public void TestBasic() { var fs = new PhysicalFileSystem(); var path = fs.ConvertPathFromInternal(SystemPath); // Create a filesystem / on the current folder of this assembly var subfs = new SubFileSystem(fs, path); // This test is basically testing the two methods (ConvertPathToDelegate and ConvertPathFromDelegate) in SubFileSystem var files = subfs.EnumeratePaths("/").Select(info => info.GetName()).ToList(); var expectedFiles = fs.EnumeratePaths(path).Select(info => info.GetName()).ToList(); Assert.True(files.Count > 0); Assert.Equal(expectedFiles, files); // Check that SubFileSystem is actually checking that the directory exists in the delegate filesystem Assert.Throws <DirectoryNotFoundException>(() => new SubFileSystem(fs, path / "does_not_exist")); Assert.Throws <InvalidOperationException>(() => subfs.ConvertPathFromInternal(@"C:\")); // TODO: We could add another test just to make sure that files can be created...etc. But the test above should already cover the code provided in SubFileSystem }
public void TestDirectorySpecial() { var fs = new PhysicalFileSystem(); // CreateDirectory Assert.True(fs.DirectoryExists("/")); if (IsWindows) { var directories = fs.EnumerateDirectories("/").ToList(); Assert.Equal(new List <UPath>() { "/mnt" }, directories); var drives = fs.EnumerateDirectories("/mnt").ToList(); Assert.True(drives.Count > 0); var allDrives = DriveInfo.GetDrives().Select(d => d.Name[0].ToString().ToLowerInvariant()).ToList(); var driveNames = drives.Select(d => d.GetName()).ToList(); Assert.Equal(allDrives, driveNames); Assert.True(fs.DirectoryExists("/")); Assert.True(fs.DirectoryExists("/mnt")); Assert.True(fs.DirectoryExists(drives[0])); var files = fs.EnumerateFiles("/").ToList(); Assert.True(files.Count == 0); files = fs.EnumerateFiles("/mnt").ToList(); Assert.True(files.Count == 0); var paths = fs.EnumeratePaths("/").ToList(); Assert.Equal(new List <UPath>() { "/mnt" }, paths); } }