Skip to content

Commit

Permalink
Add missing tests (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Apr 9, 2024
1 parent 1b79aaf commit e9bffe9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Testably.Abstractions.Internal;
internal static class ZipUtilities
{
private const string SearchPattern = "*";
private static readonly DateTime FallbackTime = new(1980, 1, 1, 0, 0, 0);

internal static IZipArchiveEntry CreateEntryFromFile(
IZipArchive destination,
Expand All @@ -32,7 +33,7 @@ internal static IZipArchiveEntry CreateEntryFromFile(

if (lastWrite.Year is < 1980 or > 2107)
{
lastWrite = new DateTime(1980, 1, 1, 0, 0, 0);
lastWrite = FallbackTime;
}

entry.LastWriteTime = new DateTimeOffset(lastWrite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ public void CreateFromDirectory_ShouldZipDirectoryContent()
FileSystem.File.ReadAllBytes("foo/bar/test.txt"));
}

#if FEATURE_COMPRESSION_STREAM
[SkippableFact]
public void CreateFromDirectory_WithReadOnlyStream_ShouldThrowArgumentException()
{
FileSystem.Initialize()
.WithFile("target.zip")
.WithSubdirectory("foo").Initialized(s => s
.WithFile("test.txt"));
using FileSystemStream stream = FileSystem.FileStream.New(
"target.zip", FileMode.Open, FileAccess.Read);

Exception? exception = Record.Exception(() =>
{
// ReSharper disable once AccessToDisposedClosure
FileSystem.ZipFile().CreateFromDirectory("foo", stream);
});

exception.Should().BeException<ArgumentException>(
paramName: "destination",
hResult: -2147024809,
messageContains: "stream is unwritable");
}
#endif

#if FEATURE_COMPRESSION_STREAM
[SkippableTheory]
[AutoData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,30 @@ public void ExtractToDirectory_WithStream_WithoutOverwriteAndExistingFile_Should
.Should().NotBe(contents);
}
#endif

#if FEATURE_COMPRESSION_STREAM
[SkippableFact]
public void ExtractToDirectory_WithWriteOnlyStream_ShouldThrowArgumentException()
{
FileSystem.Initialize()
.WithFile("target.zip")
.WithSubdirectory("foo").Initialized(s => s
.WithFile("test.txt"));
using FileSystemStream stream = FileSystem.FileStream.New(
"target.zip", FileMode.Open, FileAccess.Write);

FileSystem.ZipFile().CreateFromDirectory("foo", stream);

Exception? exception = Record.Exception(() =>
{
// ReSharper disable once AccessToDisposedClosure
FileSystem.ZipFile().ExtractToDirectory(stream, "bar");
});

exception.Should().BeException<ArgumentException>(
paramName: "source",
hResult: -2147024809,
messageContains: "stream is unreadable");
}
#endif
}

0 comments on commit e9bffe9

Please sign in to comment.