diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs index e0e776236..61b96f428 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs @@ -223,6 +223,10 @@ public override void Flush() InternalFlush(); } + /// + public override void Flush(bool flushToDisk) + => InternalFlush(); + /// public override Task FlushAsync(CancellationToken cancellationToken) { diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs index 1096c36aa..2d5755b8a 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs @@ -41,5 +41,9 @@ public void SetAccessControl(object value) throw new ArgumentException("value must be of type `FileSecurity`"); } } + + /// + public override void Flush(bool flushToDisk) + => fileStream.Flush(flushToDisk); } } \ No newline at end of file diff --git a/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs b/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs index 09610d904..435528a9c 100644 --- a/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs +++ b/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs @@ -128,6 +128,10 @@ public override void EndWrite(IAsyncResult asyncResult) public override void Flush() => _stream.Flush(); + /// + public virtual void Flush(bool flushToDisk) + => _stream.Flush(); + /// public override Task FlushAsync(CancellationToken cancellationToken) => _stream.FlushAsync(cancellationToken); diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index 69f541c59..34a5e620e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -206,5 +206,25 @@ public void MockFileStream_Flush_ShouldNotChangePosition() Assert.AreEqual(200, stream.Position); } } + + [Test] + public void MockFileStream_FlushBool_ShouldNotChangePosition([Values] bool flushToDisk) + { + // Arrange + var fileSystem = new MockFileSystem(); + var path = XFS.Path("C:\\test"); + fileSystem.AddFile(path, new MockFileData(new byte[0])); + + using (var stream = fileSystem.FileInfo.New(path).OpenWrite()) + { + // Act + stream.Write(new byte[400], 0, 400); + stream.Seek(200, SeekOrigin.Begin); + stream.Flush(flushToDisk); + + // Assert + Assert.AreEqual(200, stream.Position); + } + } } }