From 38b4f7c7b8a3e2b7c84abaca8186013af3572e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 10 May 2023 18:34:21 +0200 Subject: [PATCH 1/3] Prepare changes for support of Flush(bool flushToDisk) in System.IO.Abstractions --- .../FileSystem/FileStreamMock.cs | 4 ++++ .../FileSystem/FileStream/Tests.cs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs index a21f2095b..face9b6ee 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs @@ -189,6 +189,10 @@ public override void Flush() InternalFlush(); } + /// + public override void Flush(bool flushToDisk) + => Flush(); + /// public override Task FlushAsync(CancellationToken cancellationToken) { diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs index 0fd5f4b69..b38a47bb1 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs @@ -162,6 +162,22 @@ public void Flush_ShouldNotChangePosition( stream.Position.Should().Be(2); } + [SkippableTheory] + [InlineAutoData(false)] + [InlineAutoData(true)] + public void Flush_WriteToDisk_ShouldNotChangePosition( + bool flushToDisk, string path, byte[] bytes) + { + using FileSystemStream stream = FileSystem.File.Create(path); + stream.Write(bytes, 0, bytes.Length); + stream.Seek(2, SeekOrigin.Begin); + stream.Position.Should().Be(2); + + stream.Flush(flushToDisk); + + stream.Position.Should().Be(2); + } + [SkippableTheory] [AutoData] public void Flush_ShouldNotUpdateFileContentWhenAlreadyFlushed( From b8be11c60f197615228252b824777ac30b933fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 10 May 2023 19:48:14 +0200 Subject: [PATCH 2/3] feat: add initializer options to create the temporary directory. (#305) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add options to the FileSystemInitializer with the option to automatically create the temporary directory. If this is not set (or the file system is not initialized) `Path.GetTempPath()` will not exist. This fixes the issue in System.IO.Abstractions: https://github.com/TestableIO/System.IO.Abstractions/issues/983 --------- Co-authored-by: Valentin Breuß --- .../FileSystemInitializerExtensions.cs | 15 ++++++++++++--- .../FileSystemInitializerOptions.cs | 12 ++++++++++++ .../FileSystemInitializerExtensionsTests.cs | 17 +++++++++++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 Source/Testably.Abstractions.Testing/FileSystemInitializerOptions.cs diff --git a/Source/Testably.Abstractions.Testing/FileSystemInitializerExtensions.cs b/Source/Testably.Abstractions.Testing/FileSystemInitializerExtensions.cs index 87bb1934c..58e65b5b7 100644 --- a/Source/Testably.Abstractions.Testing/FileSystemInitializerExtensions.cs +++ b/Source/Testably.Abstractions.Testing/FileSystemInitializerExtensions.cs @@ -15,16 +15,18 @@ public static class FileSystemInitializerExtensions /// Initializes the in the working directory with test data. /// public static IFileSystemInitializer Initialize( - this TFileSystem fileSystem) + this TFileSystem fileSystem, + Action? options = null) where TFileSystem : IFileSystem - => fileSystem.InitializeIn("."); + => fileSystem.InitializeIn(".", options); /// /// Initializes the in the with test data. /// public static IFileSystemInitializer InitializeIn( this TFileSystem fileSystem, - string basePath) + string basePath, + Action? options = null) where TFileSystem : IFileSystem { if (Path.IsPathRooted(basePath) && @@ -36,6 +38,13 @@ public static IFileSystemInitializer InitializeIn( fileSystem.Directory.CreateDirectory(basePath); fileSystem.Directory.SetCurrentDirectory(basePath); + FileSystemInitializerOptions optionsValue = new(); + options?.Invoke(optionsValue); + if (optionsValue.InitializeTempDirectory) + { + fileSystem.Directory.CreateDirectory(Path.GetTempPath()); + } + return new FileSystemInitializer(fileSystem, "."); } diff --git a/Source/Testably.Abstractions.Testing/FileSystemInitializerOptions.cs b/Source/Testably.Abstractions.Testing/FileSystemInitializerOptions.cs new file mode 100644 index 000000000..94d16e852 --- /dev/null +++ b/Source/Testably.Abstractions.Testing/FileSystemInitializerOptions.cs @@ -0,0 +1,12 @@ +namespace Testably.Abstractions.Testing; + +/// +/// Options for the file system initializer. +/// +public class FileSystemInitializerOptions +{ + /// + /// If set to create the directory at . + /// + public bool InitializeTempDirectory { get; set; } = true; +} diff --git a/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs index 739c3d1e8..159a5d968 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs @@ -33,7 +33,7 @@ public void Initialize_WithAFile_WithExtension_ShouldCreateFileWithExtension( public void Initialize_WithASubdirectory_ShouldCreateDirectory() { MockFileSystem sut = new(); - sut.Initialize().WithASubdirectory(); + sut.InitializeIn("base-directory").WithASubdirectory(); sut.Directory.EnumerateDirectories(".").Should().ContainSingle(); } @@ -97,7 +97,7 @@ public void Initialize_WithFile_ShouldCreateFileWithGivenFileName(string fileNam public void Initialize_WithNestedSubdirectories_ShouldCreateAllNestedDirectories() { MockFileSystem sut = new(); - sut.Initialize() + sut.InitializeIn("base-directory") .WithSubdirectory("foo").Initialized(d => d .WithSubdirectory("bar").Initialized(s => s .WithSubdirectory("xyz"))); @@ -111,6 +111,19 @@ public void Initialize_WithNestedSubdirectories_ShouldCreateAllNestedDirectories result.Should().Contain(sut.Path.Combine(".", "foo", "bar", "xyz")); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Initialize_WithOptions_ShouldConsiderValueOfInitializeTempDirectory( + bool initializeTempDirectory) + { + MockFileSystem sut = new(); + + sut.Initialize(options => options.InitializeTempDirectory = initializeTempDirectory); + + sut.Directory.Exists(sut.Path.GetTempPath()).Should().Be(initializeTempDirectory); + } + [Theory] [AutoData] public void Initialize_WithSubdirectory_Existing_ShouldThrowTestingException( From b5ec02e44d4407e09b31504e3de035403f9ca229 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 12 May 2023 18:48:54 +0200 Subject: [PATCH 3/3] chore(deps): update dependency testableio.system.io.abstractions to v19.2.26 (#306) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [TestableIO.System.IO.Abstractions](https://togithub.com/TestableIO/System.IO.Abstractions) | nuget | patch | `19.2.22` -> `19.2.26` | --- ### Release Notes
TestableIO/System.IO.Abstractions ### [`v19.2.26`](https://togithub.com/TestableIO/System.IO.Abstractions/releases/tag/v19.2.26) ##### What's Changed - fix: Refresh FileInfo & DirectoryInfo after adding to MockFileSystem by [@​rcdailey](https://togithub.com/rcdailey) in [https://github.com/TestableIO/System.IO.Abstractions/pull/984](https://togithub.com/TestableIO/System.IO.Abstractions/pull/984) **Full Changelog**: https://github.com/TestableIO/System.IO.Abstractions/compare/v19.2.25...v19.2.26 ### [`v19.2.25`](https://togithub.com/TestableIO/System.IO.Abstractions/releases/tag/v19.2.25) #### What's Changed - chore(deps): update dependency githubactionstestlogger to v2.1.0 by [@​renovate](https://togithub.com/renovate) in [https://github.com/TestableIO/System.IO.Abstractions/pull/986](https://togithub.com/TestableIO/System.IO.Abstractions/pull/986) - chore(deps): update dependency nerdbank.gitversioning to v3.6.132 by [@​renovate](https://togithub.com/renovate) in [https://github.com/TestableIO/System.IO.Abstractions/pull/987](https://togithub.com/TestableIO/System.IO.Abstractions/pull/987) - feat: Add Flush(bool) to FileSystemStream. by [@​gregington](https://togithub.com/gregington) in [https://github.com/TestableIO/System.IO.Abstractions/pull/985](https://togithub.com/TestableIO/System.IO.Abstractions/pull/985) **Full Changelog**: https://github.com/TestableIO/System.IO.Abstractions/compare/v19.2.22...v19.2.25
--- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/Testably/Testably.Abstractions). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Examples/Directory.Build.props | 2 +- .../Testably.Abstractions.Interface.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Directory.Build.props b/Examples/Directory.Build.props index 7ab6b364c..36eb4c4cf 100644 --- a/Examples/Directory.Build.props +++ b/Examples/Directory.Build.props @@ -36,7 +36,7 @@ - + diff --git a/Source/Testably.Abstractions.Interface/Testably.Abstractions.Interface.csproj b/Source/Testably.Abstractions.Interface/Testably.Abstractions.Interface.csproj index aa80c6e8d..044c280af 100644 --- a/Source/Testably.Abstractions.Interface/Testably.Abstractions.Interface.csproj +++ b/Source/Testably.Abstractions.Interface/Testably.Abstractions.Interface.csproj @@ -18,7 +18,7 @@ - +