Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;

Expand All @@ -9,7 +8,7 @@ namespace System.IO.Abstractions.TestingHelpers

/// <inheritdoc />
[Serializable]
public class MockFileSystem : IFileSystem, IMockFileDataAccessor
public class MockFileSystem : FileSystemBase, IMockFileDataAccessor
{
private const string DEFAULT_CURRENT_DIRECTORY = @"C:\";
private const string TEMP_DIRECTORY = @"C:\temp";
Expand Down Expand Up @@ -69,21 +68,21 @@ public MockFileSystem(IDictionary<string, MockFileData> files, string currentDir
/// <inheritdoc />
public StringOperations StringOperations { get; }
/// <inheritdoc />
public IFile File { get; }
public override IFile File { get; }
/// <inheritdoc />
public IDirectory Directory { get; }
public override IDirectory Directory { get; }
/// <inheritdoc />
public IFileInfoFactory FileInfo { get; }
public override IFileInfoFactory FileInfo { get; }
/// <inheritdoc />
public IFileStreamFactory FileStream { get; }
public override IFileStreamFactory FileStream { get; }
/// <inheritdoc />
public IPath Path { get; }
public override IPath Path { get; }
/// <inheritdoc />
public IDirectoryInfoFactory DirectoryInfo { get; }
public override IDirectoryInfoFactory DirectoryInfo { get; }
/// <inheritdoc />
public IDriveInfoFactory DriveInfo { get; }
public override IDriveInfoFactory DriveInfo { get; }
/// <inheritdoc />
public IFileSystemWatcherFactory FileSystemWatcher { get; set; }
public override IFileSystemWatcherFactory FileSystemWatcher { get; }
/// <inheritdoc />
public IFileSystem FileSystem => this;
/// <inheritdoc />
Expand Down
18 changes: 9 additions & 9 deletions src/System.IO.Abstractions/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
/// <inheritdoc />
[Serializable]
public class FileSystem : IFileSystem
public class FileSystem : FileSystemBase
{
/// <inheritdoc />
public FileSystem()
Expand All @@ -18,27 +18,27 @@ public FileSystem()
}

/// <inheritdoc />
public IDirectory Directory { get; }
public override IDirectory Directory { get; }

/// <inheritdoc />
public IFile File { get; }
public override IFile File { get; }

/// <inheritdoc />
public IFileInfoFactory FileInfo { get; }
public override IFileInfoFactory FileInfo { get; }

/// <inheritdoc />
public IFileStreamFactory FileStream { get; }
public override IFileStreamFactory FileStream { get; }

/// <inheritdoc />
public IPath Path { get; }
public override IPath Path { get; }

/// <inheritdoc />
public IDirectoryInfoFactory DirectoryInfo { get; }
public override IDirectoryInfoFactory DirectoryInfo { get; }

/// <inheritdoc />
public IDriveInfoFactory DriveInfo { get; }
public override IDriveInfoFactory DriveInfo { get; }

/// <inheritdoc />
public IFileSystemWatcherFactory FileSystemWatcher { get; }
public override IFileSystemWatcherFactory FileSystemWatcher { get; }
}
}
31 changes: 31 additions & 0 deletions src/System.IO.Abstractions/FileSystemBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace System.IO.Abstractions
{
/// <inheritdoc />
[Serializable]
public abstract class FileSystemBase : IFileSystem
{
/// <inheritdoc />
public abstract IDirectory Directory { get; }

/// <inheritdoc />
public abstract IFile File { get; }

/// <inheritdoc />
public abstract IFileInfoFactory FileInfo { get; }

/// <inheritdoc />
public abstract IFileStreamFactory FileStream { get; }

/// <inheritdoc />
public abstract IPath Path { get; }

/// <inheritdoc />
public abstract IDirectoryInfoFactory DirectoryInfo { get; }

/// <inheritdoc />
public abstract IDriveInfoFactory DriveInfo { get; }

/// <inheritdoc />
public abstract IFileSystemWatcherFactory FileSystemWatcher { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,23 +393,24 @@ public void MockFileSystem_DefaultState_DefaultTempDirectoryExists()
}

[Test]
public void MockFileSystem_FileSystemWatcher_PathShouldBeAssignable()
public void MockFileSystem_FileSystemWatcher_Can_Be_Overridden()
{
var path = XFS.Path(@"C:\root");
var fileSystem = new MockFileSystem { FileSystemWatcher = new TestFileSystemWatcherFactory() };
var fileSystem = new TestFileSystem(new TestFileSystemWatcherFactory());
var watcher = fileSystem.FileSystemWatcher.CreateNew(path);
Assert.AreEqual(path, watcher.Path);
}

[Test]
public void MockFileSystem_FileSystemWatcher_PathAndFilterShouldBeAssignable()
private class TestFileSystem : MockFileSystem
{
var path = XFS.Path(@"C:\root");
var filter = "*.txt";
var fileSystem = new MockFileSystem { FileSystemWatcher = new TestFileSystemWatcherFactory() };
var watcher = fileSystem.FileSystemWatcher.CreateNew(path, filter);
Assert.AreEqual(path, watcher.Path);
Assert.AreEqual(filter, watcher.Filter);
private readonly IFileSystemWatcherFactory fileSystemWatcherFactory;

public TestFileSystem(IFileSystemWatcherFactory fileSystemWatcherFactory)
{
this.fileSystemWatcherFactory = fileSystemWatcherFactory;
}

public override IFileSystemWatcherFactory FileSystemWatcher => fileSystemWatcherFactory;
}

private class TestFileSystemWatcherFactory : IFileSystemWatcherFactory
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "15.0",
"version": "16.0",
"assemblyVersion": {
"precision": "major"
},
Expand Down