diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs index 61b96f428..197fffd43 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs @@ -9,6 +9,24 @@ namespace System.IO.Abstractions.TestingHelpers [Serializable] public class MockFileStream : FileSystemStream, IFileSystemAclSupport { + /// + /// Wrapper around a with no backing store, which + /// is used as a replacement for a . As such + /// it implements the same properties and methods as a . + /// + public new static FileSystemStream Null { get; } = new NullFileSystemStream(); + + private class NullFileSystemStream : FileSystemStream + { + /// + /// Initializes a new instance of . + /// + public NullFileSystemStream() : base(Null, ".", true) + { + + } + } + private readonly IMockFileDataAccessor mockFileDataAccessor; private readonly string path; private readonly FileAccess access = FileAccess.ReadWrite; diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index 34a5e620e..8a32806d4 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -226,5 +226,24 @@ public void MockFileStream_FlushBool_ShouldNotChangePosition([Values] bool flush Assert.AreEqual(200, stream.Position); } } + + [Test] + public void MockFileStream_Null_ShouldReturnSingletonObject() + { + var result1 = MockFileStream.Null; + var result2 = MockFileStream.Null; + + Assert.AreSame(result1, result2); + } + + [Test] + public void MockFileStream_Null_ShouldHaveExpectedProperties() + { + var result = MockFileStream.Null; + + Assert.AreEqual(result.Name, "."); + Assert.AreEqual(result.Length, 0); + Assert.AreEqual(result.IsAsync, true); + } } }