From 4ef1c3a7d5f6b9bffb399054fd9b7676220f5201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Fri, 8 Nov 2024 18:19:02 +0100 Subject: [PATCH] fix: async dispose for `FileSystemStream` (#1163) Fix #1162 --- .../FileSystemStream.cs | 9 --------- .../MockFileStreamTests.cs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs b/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs index 8709ecbce..c8553e740 100644 --- a/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs +++ b/src/TestableIO.System.IO.Abstractions/FileSystemStream.cs @@ -223,15 +223,6 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } -#if FEATURE_ASYNC_FILE - /// - public override async ValueTask DisposeAsync() - { - await _stream.DisposeAsync(); - await base.DisposeAsync(); - } -#endif - /// /// Allows to cast the internal Stream to a FileStream /// diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index a55257c27..06eedd52c 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -283,6 +283,18 @@ public void MockFileStream_Null_ShouldReturnSingletonObject() Assert.That(result1, Is.SameAs(result2)); } + + #if FEATURE_ASYNC_FILE + [Test] + public async Task MockFileStream_DisposeAsync_ShouldNotThrow() + { + var fileSystem = new MockFileSystem(); + fileSystem.File.WriteAllText("foo.txt", ""); + { + await using var reportStream = fileSystem.File.OpenRead("foo.txt"); + } + } + #endif [Test] public void MockFileStream_Null_ShouldHaveExpectedProperties()