public async void SimulationModeFileSystem_EnumerateFiles_AddedFiles() { var fileSystem = new SimulationModeFileSystem(); var dirPath = Directory.GetCurrentDirectory(); var expected = Directory.EnumerateFiles(dirPath, "*.*", SearchOption.TopDirectoryOnly); var actual = fileSystem.EnumerateFiles(dirPath, "*.*", SearchOption.TopDirectoryOnly); Assert.Equal(expected, actual); var contents = "DummyContents"; byte[] bytes = Encoding.UTF8.GetBytes(contents); await fileSystem.AddFileAsync(Path.Combine(dirPath, "DummyOutputPath.txt"), new MemoryStream(bytes)); actual = fileSystem.EnumerateFiles(dirPath, "*.*", SearchOption.TopDirectoryOnly); Assert.Contains(actual, f => f.Equals(Path.Combine(dirPath, "DummyOutputPath.txt"))); actual = fileSystem.EnumerateFiles(dirPath, "DummyOutputPat?.txt", SearchOption.TopDirectoryOnly); Assert.Contains(actual, f => f.Equals(Path.Combine(dirPath, "DummyOutputPath.txt"))); actual = fileSystem.EnumerateFiles(dirPath, "*OutputPath.t?t", SearchOption.TopDirectoryOnly); Assert.Contains(actual, f => f.Equals(Path.Combine(dirPath, "DummyOutputPath.txt"))); fileSystem.CreateDirectory(Path.Combine(dirPath, "test_dir")); await fileSystem.AddFileAsync(Path.Combine(dirPath, "test_dir", "TestFile.abc"), new MemoryStream(bytes)); actual = fileSystem.EnumerateFiles(dirPath, "*.*", SearchOption.AllDirectories); Assert.Contains(actual, f => f.Equals(Path.Combine(dirPath, "DummyOutputPath.txt"))); Assert.Contains(actual, f => f.Equals(Path.Combine(dirPath, "test_dir", "TestFile.abc"))); actual = fileSystem.EnumerateFiles(dirPath, "*.abc", SearchOption.AllDirectories); Assert.DoesNotContain(actual, f => f.Equals(Path.Combine(dirPath, "DummyOutputPath.txt"))); Assert.Contains(actual, f => f.Equals(Path.Combine(dirPath, "test_dir", "TestFile.abc"))); }
public async void SimulationModeFileSystem_EditFile() { var fileSystem = new SimulationModeFileSystem(); var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); File.WriteAllText(path, ""); var contents = "DummyContents"; byte[] bytes = Encoding.UTF8.GetBytes(contents); await fileSystem.AddFileAsync(path, new MemoryStream(bytes)); Assert.Equal(path, fileSystem.FileSystemChanges.First().FullPath); Assert.Equal("DummyContents", fileSystem.FileSystemChanges.First().FileContents); Assert.Equal(FileSystemChangeType.EditFile, fileSystem.FileSystemChanges.First().FileSystemChangeType); try { File.Delete(path); } catch { // do nothing. } }
public async void SimulationModeFileSystem_AddFile() { var fileSystem = new SimulationModeFileSystem(); var contents = "DummyContents"; byte[] bytes = Encoding.UTF8.GetBytes(contents); var currentDir = Directory.GetCurrentDirectory(); await fileSystem.AddFileAsync(Path.Combine(currentDir, "DummyOutputPath.txt"), new MemoryStream(bytes)); Assert.Equal(Path.Combine(currentDir, "DummyOutputPath.txt"), fileSystem.FileSystemChanges.First().FullPath); Assert.Equal("DummyContents", fileSystem.FileSystemChanges.First().FileContents); Assert.Equal(FileSystemChangeType.AddFile, fileSystem.FileSystemChanges.First().FileSystemChangeType); }