public void AttributesFail() { var mountfs = new MountFileSystem(); Assert.Throws <FileNotFoundException>(() => mountfs.GetAttributes("/toto.txt")); Assert.Throws <FileNotFoundException>(() => mountfs.SetAttributes("/toto.txt", FileAttributes.Normal)); }
public void EnumerateDoesntExist() { var mountFs = new MountFileSystem(); mountFs.Mount("/x", new MemoryFileSystem()); Assert.Throws <DirectoryNotFoundException>(() => mountFs.EnumeratePaths("/y", "*", SearchOption.AllDirectories, SearchTarget.Both).ToList()); }
public void EnumerateMountsOverride() { var baseFs = new MemoryFileSystem(); baseFs.CreateDirectory("/foo/bar"); baseFs.WriteAllText("/base.txt", "test"); baseFs.WriteAllText("/foo/base.txt", "test"); baseFs.WriteAllText("/foo/bar/base.txt", "test"); var mountedFs = new MemoryFileSystem(); mountedFs.WriteAllText("/mounted.txt", "test"); var deepMountedFs = new MemoryFileSystem(); deepMountedFs.WriteAllText("/deep_mounted.txt", "test"); var mountFs = new MountFileSystem(baseFs); mountFs.Mount("/foo", mountedFs); mountFs.Mount("/foo/bar", deepMountedFs); var expected = new List <UPath> { "/base.txt", "/foo", "/foo/bar", "/foo/mounted.txt", "/foo/bar/deep_mounted.txt" }; var actual = mountFs.EnumeratePaths("/", "*", SearchOption.AllDirectories).ToList(); Assert.Equal(expected, actual); }
public void OpenFileFail() { var mountfs = new MountFileSystem(); Assert.Throws <FileNotFoundException>(() => mountfs.OpenFile("/toto.txt", FileMode.Open, FileAccess.Read)); Assert.Throws <UnauthorizedAccessException>(() => mountfs.OpenFile("/toto.txt", FileMode.Create, FileAccess.Read)); }
public void TimesFail() { var mountfs = new MountFileSystem(); Assert.Throws <FileNotFoundException>(() => mountfs.SetCreationTime("/toto.txt", DateTime.Now)); Assert.Throws <FileNotFoundException>(() => mountfs.SetLastAccessTime("/toto.txt", DateTime.Now)); Assert.Throws <FileNotFoundException>(() => mountfs.SetLastWriteTime("/toto.txt", DateTime.Now)); }
public void CopyFileFail() { var mountfs = new MountFileSystem(); mountfs.Mount("/dir1", new MemoryFileSystem()); Assert.Throws <FileNotFoundException>(() => mountfs.CopyFile("/test", "/test2", true)); Assert.Throws <DirectoryNotFoundException>(() => mountfs.CopyFile("/dir1/test.txt", "/test2", true)); }
public void EnumerateEmptyOnRoot() { var mountFs = new MountFileSystem(); var expected = Array.Empty <UPath>(); var actual = mountFs.EnumeratePaths("/", "*", SearchOption.AllDirectories, SearchTarget.Both).ToList(); Assert.Equal(expected, actual); }
public void Read() { // check the inputPath if (!Directory.Exists(InputPath)) { throw new DirectoryNotFoundException("The input path is not a valid directory"); } // change the (probably) relative path to an absolute one InputPath = Path.GetFullPath(InputPath); // again.. change the (probably) relative path to an absolute one OutputPath = Path.GetFullPath(OutputPath); _logger.Info($"Source path: '{InputPath}'"); _logger.Info($"Output path: '{OutputPath}'"); // check the project configuration file foreach (var extension in new[] { "yaml", "yml" }) { var path = Path.Join(InputPath, $"project.{extension}"); if (File.Exists(path)) { ProjectConfigurationPath = path; break; } } if (string.IsNullOrWhiteSpace(ProjectConfigurationPath)) { throw new FileNotFoundException("The project configuration file does not exist"); } _logger.Info($"Reading the project file '{ProjectConfigurationPath}'"); var yamlDeserializer = new Deserializer(); var configStream = File.OpenText(ProjectConfigurationPath); ProjectData = yamlDeserializer.Deserialize <ProjectData>(configStream); _fileSystem = new MountFileSystem(new SubFileSystem(new PhysicalFileSystem(), OsPathToUPath(InputPath))); foreach (var i in ProjectData.Includes) { i.Path = Path.GetFullPath(i.Path, InputPath); if (!Directory.Exists(i.Path)) { throw new DirectoryNotFoundException($"The include directory does not exist: '{i.Path}'"); } _fileSystem.Mount(i.Mount, new SubFileSystem(new PhysicalFileSystem(), OsPathToUPath(i.Path))); } _logger.Info(ProjectData); }
public TestMountFileSystemCompatSub() { // Check that MountFileSystem is working with a mount with the compat test var mountfs = new MountFileSystem(); mountfs.Mount("/customMount", new MemoryFileSystem()); // Use a SubFileSystem to fake the mount to a root folder fs = new SubFileSystem(mountfs, "/customMount"); }
public void DeleteDirectoryFail() { var mountfs = new MountFileSystem(); mountfs.Mount("/dir1", new MemoryFileSystem()); Assert.Throws <UnauthorizedAccessException>(() => mountfs.DeleteDirectory("/dir1", true)); Assert.Throws <UnauthorizedAccessException>(() => mountfs.DeleteDirectory("/dir1", false)); Assert.Throws <DirectoryNotFoundException>(() => mountfs.DeleteDirectory("/dir2", false)); }
protected MountFileSystem GetCommonMountFileSystemWithOnlyBackup() { // Check on MountFileSystem directly with backup mount var fs = new MemoryFileSystem(); CreateFolderStructure(fs); var mountfs = new MountFileSystem(fs); return(mountfs); }
public void MoveDirectoryFail() { var mountfs = new MountFileSystem(); mountfs.Mount("/dir1", new MemoryFileSystem()); mountfs.Mount("/dir2", new MemoryFileSystem()); Assert.Throws <UnauthorizedAccessException>(() => mountfs.MoveDirectory("/dir1", "/dir2/yyy")); Assert.Throws <UnauthorizedAccessException>(() => mountfs.MoveDirectory("/dir1/xxx", "/dir2")); Assert.Throws <NotSupportedException>(() => mountfs.MoveDirectory("/dir1/xxx", "/dir2/yyy")); }
public void DirectoryExistsPartialMountName() { var fs = new MemoryFileSystem(); var mountFs = new MountFileSystem(); mountFs.Mount("/x/y/z", fs); Assert.True(mountFs.DirectoryExists("/x")); Assert.True(mountFs.DirectoryExists("/x/y")); Assert.True(mountFs.DirectoryExists("/x/y/z")); Assert.False(mountFs.DirectoryExists("/z")); }
public void DirectoryEntryPartialMountName() { var fs = new MemoryFileSystem(); fs.CreateDirectory("/w"); var mountFs = new MountFileSystem(); mountFs.Mount("/x/y/z", fs); Assert.NotNull(mountFs.GetDirectoryEntry("/x")); Assert.NotNull(mountFs.GetDirectoryEntry("/x/y")); Assert.NotNull(mountFs.GetDirectoryEntry("/x/y/z")); Assert.NotNull(mountFs.GetDirectoryEntry("/x/y/z/w")); }
public void TestMount() { var fs = new MountFileSystem(); var memfs = new MemoryFileSystem(); Assert.Throws <ArgumentNullException>(() => fs.Mount(null, memfs)); Assert.Throws <ArgumentNullException>(() => fs.Mount("/test", null)); Assert.Throws <ArgumentException>(() => fs.Mount("test", memfs)); Assert.Throws <ArgumentException>(() => fs.Mount("/", memfs)); Assert.False(fs.IsMounted("/test")); fs.Mount("/test", memfs); Assert.True(fs.IsMounted("/test")); Assert.Throws <ArgumentException>(() => fs.Mount("/test", memfs)); Assert.Throws <ArgumentException>(() => fs.Mount("/test", fs)); Assert.Throws <ArgumentNullException>(() => fs.Unmount(null)); Assert.Throws <ArgumentException>(() => fs.Unmount("test")); Assert.Throws <ArgumentException>(() => fs.Unmount("/")); Assert.Throws <ArgumentException>(() => fs.Unmount("/test/a")); Assert.Throws <ArgumentException>(() => fs.Unmount("/test/a/b")); Assert.Throws <ArgumentException>(() => fs.Unmount("/test2")); fs.Mount("/test2", memfs); Assert.True(fs.IsMounted("/test")); Assert.True(fs.IsMounted("/test2")); Assert.Equal(new Dictionary <UPath, IFileSystem>() { { "/test", memfs }, { "/test2", memfs }, }, fs.GetMounts()); fs.Unmount("/test"); Assert.False(fs.IsMounted("/test")); Assert.True(fs.IsMounted("/test2")); fs.Unmount("/test2"); Assert.Equal(0, fs.GetMounts().Count); var innerFs = GetCommonMemoryFileSystem(); fs.Mount("/x/y", innerFs); fs.Mount("/x/y/b", innerFs); Assert.True(fs.FileExists("/x/y/A.txt")); Assert.True(fs.FileExists("/x/y/b/A.txt")); }
public void ReplaceFileFail() { var mountfs = new MountFileSystem(); var memfs1 = new MemoryFileSystem(); memfs1.WriteAllText("/file.txt", "content1"); var memfs2 = new MemoryFileSystem(); memfs2.WriteAllText("/file2.txt", "content1"); mountfs.Mount("/dir1", memfs1); mountfs.Mount("/dir2", memfs2); Assert.Throws <FileNotFoundException>(() => mountfs.ReplaceFile("/dir1/file.txt", "/dir1/to.txt", "/dir1/to.bak", true)); Assert.Throws <FileNotFoundException>(() => mountfs.ReplaceFile("/dir1/to.txt", "/dir1/file.txt", "/dir1/to.bak", true)); Assert.Throws <NotSupportedException>(() => mountfs.ReplaceFile("/dir1/file.txt", "/dir2/file2.txt", null, true)); }
public void MoveFileFail() { var mountfs = new MountFileSystem(); var memfs1 = new MemoryFileSystem(); memfs1.WriteAllText("/file.txt", "content1"); var memfs2 = new MemoryFileSystem(); memfs2.WriteAllText("/file2.txt", "content1"); mountfs.Mount("/dir1", memfs1); mountfs.Mount("/dir2", memfs2); Assert.Throws <DirectoryNotFoundException>(() => mountfs.MoveFile("/dir1/file.txt", "/xxx/yyy.txt")); Assert.Throws <FileNotFoundException>(() => mountfs.MoveFile("/dir1/xxx", "/dir1/file1.txt")); Assert.Throws <FileNotFoundException>(() => mountfs.MoveFile("/xxx", "/dir1/file1.txt")); }
protected MountFileSystem GetCommonMountFileSystemWithMounts() { // Check on MountFileSystem // with real mount var fs = new MemoryFileSystem(); CreateFolderStructure(fs); fs.DeleteDirectory("/b", true); fs.DeleteDirectory("/C", true); var fs1 = new MemoryFileSystem(); fs1.WriteAllText("/b.i", "content"); var mountfs = new MountFileSystem(fs); mountfs.Mount("/b", fs1); mountfs.Mount("/C", new MemoryFileSystem()); return(mountfs); }
public void EnumerateDeepMountPartial() { var fs = GetCommonMemoryFileSystem(); var mountFs = new MountFileSystem(); mountFs.Mount("/x/y/z", fs); Assert.True(mountFs.FileExists("/x/y/z/A.txt")); var expected = new List <UPath> { "/x/y", "/x/y/z", "/x/y/z/a", "/x/y/z/A.txt" }; // only concerned with the first few because it should list the mount parts first var actual = mountFs.EnumeratePaths("/x", "*", SearchOption.AllDirectories).Take(4).ToList(); Assert.Equal(expected, actual); }
public void CopyAndMoveFileCross() { var mountfs = new MountFileSystem(); var memfs1 = new MemoryFileSystem(); memfs1.WriteAllText("/file1.txt", "content1"); var memfs2 = new MemoryFileSystem(); mountfs.Mount("/dir1", memfs1); mountfs.Mount("/dir2", memfs2); mountfs.CopyFile("/dir1/file1.txt", "/dir2/file2.txt", true); Assert.True(memfs2.FileExists("/file2.txt")); Assert.Equal("content1", memfs2.ReadAllText("/file2.txt")); mountfs.MoveFile("/dir1/file1.txt", "/dir2/file1.txt"); Assert.False(memfs1.FileExists("/file1.txt")); Assert.True(memfs2.FileExists("/file1.txt")); Assert.Equal("content1", memfs2.ReadAllText("/file1.txt")); }
public void GetFileLengthFail() { var mountfs = new MountFileSystem(); Assert.Throws <FileNotFoundException>(() => mountfs.GetFileLength("/toto.txt")); }
public void CreateDirectoryFail() { var mountfs = new MountFileSystem(); Assert.Throws <UnauthorizedAccessException>(() => mountfs.CreateDirectory("/test")); }
public TestMountFileSystemCompat() { // Check that the MountFileSystem is working with only a plain backup MemoryFileSystem with the compat test fs = new MountFileSystem(new MemoryFileSystem()); }
public void EnumerateFail() { var mountfs = new MountFileSystem(); Assert.Throws <DirectoryNotFoundException>(() => mountfs.EnumeratePaths("/dir").ToList()); }