diff --git a/Tests/Testably.Abstractions.Compression.Tests/ZipFile/ExtractToDirectoryTests.cs b/Tests/Testably.Abstractions.Compression.Tests/ZipFile/ExtractToDirectoryTests.cs index b56382909..0e774144c 100644 --- a/Tests/Testably.Abstractions.Compression.Tests/ZipFile/ExtractToDirectoryTests.cs +++ b/Tests/Testably.Abstractions.Compression.Tests/ZipFile/ExtractToDirectoryTests.cs @@ -88,6 +88,32 @@ public void ExtractToDirectory_Overwrite_ShouldOverwriteFile( } #endif +#if FEATURE_COMPRESSION_OVERWRITE + [SkippableTheory] + [AutoData] + public void ExtractToDirectory_WithEncoding_Overwrite_ShouldOverwriteFile( + string contents, + Encoding encoding) + { + FileSystem.Initialize() + .WithSubdirectory("bar").Initialized(s => s + .WithFile("test.txt")) + .WithSubdirectory("foo").Initialized(s => s + .WithFile("test.txt")); + FileSystem.File.WriteAllText(FileSystem.Path.Combine("foo", "test.txt"), + contents); + + FileSystem.ZipFile().CreateFromDirectory("foo", "destination.zip"); + + FileSystem.ZipFile().ExtractToDirectory("destination.zip", "bar", encoding, true); + + FileSystem.File.Exists(FileSystem.Path.Combine("bar", "test.txt")) + .Should().BeTrue(); + FileSystem.File.ReadAllText(FileSystem.Path.Combine("bar", "test.txt")) + .Should().Be(contents); + } +#endif + [SkippableTheory] [AutoData] public void ExtractToDirectory_WithEncoding_ShouldZipDirectoryContent( @@ -221,6 +247,33 @@ public void ExtractToDirectory_WithStream_Overwrite_ShouldOverwriteFile( } #endif +#if FEATURE_COMPRESSION_STREAM + [SkippableTheory] + [AutoData] + public void ExtractToDirectory_WithStream_WithEncoding_Overwrite_ShouldOverwriteFile( + string contents, + Encoding encoding) + { + FileSystem.Initialize() + .WithSubdirectory("bar").Initialized(s => s + .WithFile("test.txt")) + .WithSubdirectory("foo").Initialized(s => s + .WithFile("test.txt")); + FileSystem.File.WriteAllText(FileSystem.Path.Combine("foo", "test.txt"), + contents); + using MemoryStream stream = new(); + + FileSystem.ZipFile().CreateFromDirectory("foo", stream); + + FileSystem.ZipFile().ExtractToDirectory(stream, "bar", encoding, true); + + FileSystem.File.Exists(FileSystem.Path.Combine("bar", "test.txt")) + .Should().BeTrue(); + FileSystem.File.ReadAllText(FileSystem.Path.Combine("bar", "test.txt")) + .Should().Be(contents); + } +#endif + #if FEATURE_COMPRESSION_STREAM [SkippableTheory] [AutoData] @@ -267,6 +320,7 @@ public void ExtractToDirectory_WithStream_WithoutOverwriteAndExistingFile_Should Exception? exception = Record.Exception(() => { + // ReSharper disable once AccessToDisposedClosure FileSystem.ZipFile().ExtractToDirectory(stream, "bar"); }); diff --git a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileMockTests.cs b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileMockTests.cs index 06a5d4bac..a30f63cf6 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileMockTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileMockTests.cs @@ -9,6 +9,50 @@ namespace Testably.Abstractions.Testing.Tests.FileSystem; public class FileMockTests { +#if FEATURE_FILESYSTEM_SAFEFILEHANDLE + [Theory] + [AutoData] + public void GetAttributes_SafeFileHandle_WithMissingFile_ShouldThrowFileNotFoundException( + string path) + { + SafeFileHandle fileHandle = new(); + MockFileSystem fileSystem = new(); + fileSystem.WithSafeFileHandleStrategy( + new DefaultSafeFileHandleStrategy(_ => new SafeFileHandleMock(path))); + + Exception? exception = Record.Exception(() => + { + _ = fileSystem.File.GetAttributes(fileHandle); + }); + + exception.Should().BeOfType(); + } +#endif +#if FEATURE_FILESYSTEM_SAFEFILEHANDLE + [SkippableTheory] + [AutoData] + public void GetUnixFileMode_SafeFileHandle_ShouldThrowPlatformNotSupportedExceptionOnWindows( + string path) + { + Skip.IfNot(Test.RunsOnWindows); + + SafeFileHandle fileHandle = new(); + MockFileSystem fileSystem = new(); + fileSystem.File.WriteAllText(path, "some content"); + fileSystem.WithSafeFileHandleStrategy( + new DefaultSafeFileHandleStrategy(_ => new SafeFileHandleMock(path))); + + Exception? exception = Record.Exception(() => + { + #pragma warning disable CA1416 + fileSystem.File.GetUnixFileMode(fileHandle); + #pragma warning restore CA1416 + }); + + exception.Should().BeOfType(); + } +#endif + #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [Theory] [AutoData] @@ -30,6 +74,7 @@ public void SetAttributes_SafeFileHandle_ShouldUpdateValue( result.Should().Be(expectedAttributes); } #endif + [Theory] [AutoData] public void SetCreationTime(string path, DateTime creationTime) diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/MethodStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/MethodStatisticsTests.cs index 4a3d28a53..e5cdad206 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/MethodStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/MethodStatisticsTests.cs @@ -5,6 +5,16 @@ namespace Testably.Abstractions.Testing.Tests.Statistics; public sealed class MethodStatisticsTests { + [Fact] + public void Counter_ShouldBeInitializedWithOne() + { + MockFileSystem fileSystem = new(); + fileSystem.File.WriteAllText("foo", "bar"); + MethodStatistic sut = fileSystem.Statistics.File.Methods.First(); + + sut.Counter.Should().Be(1); + } + [Fact] public void ToString_ShouldContainName() { diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/ParameterDescriptionTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/ParameterDescriptionTests.cs index e5a6f235c..0d66d769a 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/ParameterDescriptionTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/ParameterDescriptionTests.cs @@ -49,6 +49,31 @@ public void FromParameter_WithSpan_ShouldSetIsOutParameterToFalse(int[] buffer) } #endif + [Theory] + [InlineAutoData(true)] + [InlineAutoData(false)] + public void Is_WithComparer_ShouldUseComparerResult(bool comparerResult, string value) + { + ParameterDescription sut = ParameterDescription.FromParameter(value); + + bool result = sut.Is(_ => comparerResult); + + result.Should().Be(comparerResult); + } + + [Theory] + [InlineAutoData(true)] + [InlineAutoData(false)] + public void Is_WithComparer_WithIncompatibleType_ShouldReturnFalse(bool comparerResult, + string value) + { + ParameterDescription sut = ParameterDescription.FromParameter(value); + + bool result = sut.Is(_ => comparerResult); + + result.Should().BeFalse(); + } + [Theory] [AutoData] public void Is_WithFromOutParameter_ShouldCheckForMatchingValue(int value) diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/PropertyStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/PropertyStatisticsTests.cs index 1511497eb..7ebb1852e 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/PropertyStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/PropertyStatisticsTests.cs @@ -5,6 +5,16 @@ namespace Testably.Abstractions.Testing.Tests.Statistics; public sealed class PropertyStatisticsTests { + [Fact] + public void Counter_ShouldBeInitializedWithOne() + { + MockFileSystem fileSystem = new(); + _ = fileSystem.Path.DirectorySeparatorChar; + PropertyStatistic sut = fileSystem.Statistics.Path.Properties.First(); + + sut.Counter.Should().Be(1); + } + [Fact] public void ToString_Get_ShouldContainNameAndGet() { diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Path/Tests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Path/Tests.cs index 32ca64bc9..d8fa778c9 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Path/Tests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Path/Tests.cs @@ -29,6 +29,14 @@ public void GetInvalidFileNameChars_ShouldReturnDefaultValue() result.Should().BeEquivalentTo(System.IO.Path.GetInvalidFileNameChars()); } + [SkippableFact] + public void GetInvalidPathChars_ShouldReturnDefaultValue() + { + char[] result = FileSystem.Path.GetInvalidPathChars(); + + result.Should().BeEquivalentTo(System.IO.Path.GetInvalidPathChars()); + } + [SkippableTheory] [AutoData] public void GetPathRoot_ShouldReturnDefaultValue(string path)