Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
global using AutoFixture.Xunit2;
global using FluentAssertions;
global using System;
global using System.Threading.Tasks;
global using System.IO.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<ItemGroup>
<ProjectReference Include="..\Helpers\Testably.Abstractions.Tests.SourceGenerator\Testably.Abstractions.Tests.SourceGenerator.csproj" OutputItemType="Analyzer" />
<PackageReference Include="FluentAssertions" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.ObjectModel;
using System.IO;
using System.IO.Compression;

namespace Testably.Abstractions.Compression.Tests.ZipArchive;
Expand Down Expand Up @@ -55,9 +56,9 @@ public async Task Entries_CreateMode_ShouldThrowNotSupportedException()

IZipArchive archive = FileSystem.ZipArchive().New(stream, ZipArchiveMode.Create);

Exception? exception = Record.Exception(() => archive.Entries);
ReadOnlyCollection<IZipArchiveEntry> Act() => archive.Entries;

exception.Should().BeOfType<NotSupportedException>();
await That(Act).Should().Throw<NotSupportedException>();
}

[SkippableTheory]
Expand All @@ -74,7 +75,7 @@ public async Task FileSystem_ShouldBeSet(
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

archive.FileSystem.Should().Be(FileSystem);
await That(archive.FileSystem).Should().Be(FileSystem);
}

[SkippableFact]
Expand All @@ -90,9 +91,9 @@ public async Task GetEntry_WhenNameIsNotFound_ShouldReturnNull()
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

archive.GetEntry("bar.txt").Should().BeNull();
archive.GetEntry("foo.txt").Should().BeNull();
archive.GetEntry("foo/foo.txt").Should().NotBeNull();
await That(archive.GetEntry("bar.txt")).Should().BeNull();
await That(archive.GetEntry("foo.txt")).Should().BeNull();
await That(archive.GetEntry("foo/foo.txt")).Should().NotBeNull();
}

[SkippableTheory]
Expand All @@ -108,6 +109,6 @@ public async Task Mode_ShouldBeSetCorrectly(ZipArchiveMode mode)
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", mode);

archive.Mode.Should().Be(mode);
await That(archive.Mode).Should().Be(mode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,14 @@ public async Task New_WithEntryNameEncoding_ShouldUseEncoding(
using IZipArchive readArchive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

readArchive.Entries.Count.Should().Be(1);
var singleEntry = await That(readArchive.Entries).Should().HaveSingle();
if (encodedCorrectly)
{
await That(readArchive.Entries).Should()
.Contain(e => string.Equals(e.Name, entryName, StringComparison.Ordinal));
await That(singleEntry.Name).Should().Be(entryName);
}
else
{
await That(readArchive.Entries).Should()
.NotContain(e => string.Equals(e.Name, entryName, StringComparison.Ordinal));
await That(singleEntry.Name).Should().NotBe(entryName);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO.Compression;
using FluentAssertions;
using System.IO.Compression;
using System.Text;
#if FEATURE_COMPRESSION_STREAM
using System.IO;
Expand Down Expand Up @@ -28,8 +29,8 @@ public async Task
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("bar/"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("bar/"));
}

[SkippableTheory]
Expand All @@ -46,7 +47,7 @@ public async Task CreateFromDirectory_EmptySource_DoNotIncludeBaseDirectory_Shou
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(0);
await That(archive.Entries).Should().BeEmpty();
}

[SkippableTheory]
Expand All @@ -64,8 +65,8 @@ public async Task
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("foo/"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("foo/"));
}

[SkippableTheory]
Expand All @@ -84,14 +85,14 @@ public async Task CreateFromDirectory_EntryNameEncoding_ShouldUseEncoding(
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
var singleEntry = await That(archive.Entries).Should().HaveSingle();
if (encodedCorrectly)
{
archive.Entries.Should().Contain(e => e.Name == entryName);
await That(singleEntry.Name).Should().Be(entryName);
}
else
{
archive.Entries.Should().NotContain(e => e.Name == entryName);
await That(singleEntry.Name).Should().NotBe(entryName);
}
}

Expand All @@ -110,8 +111,8 @@ public async Task CreateFromDirectory_IncludeBaseDirectory_ShouldPrependDirector
using IZipArchive archive =
FileSystem.ZipFile().Open("destination.zip", ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("foo/test.txt"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("foo/test.txt"));
}

#if FEATURE_COMPRESSION_OVERWRITE
Expand All @@ -134,8 +135,8 @@ public async Task CreateFromDirectory_Overwrite_WithEncoding_ShouldOverwriteFile
IZipArchive archive = FileSystem.ZipFile()
.Open("destination.zip", ZipArchiveMode.Read, encoding);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("test.txt"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("test.txt"));
}
#endif

Expand All @@ -152,11 +153,9 @@ public async Task CreateFromDirectory_ShouldZipDirectoryContent()

FileSystem.ZipFile().ExtractToDirectory("destination.zip", "destination");

FileSystem.File.Exists("destination/bar/test.txt")
.Should().BeTrue();
FileSystem.File.ReadAllBytes("destination/bar/test.txt")
.Should().BeEquivalentTo(
FileSystem.File.ReadAllBytes("foo/bar/test.txt"));
await That(FileSystem).Should().HaveFile("destination/bar/test.txt");
await That(FileSystem.File.ReadAllBytes("destination/bar/test.txt"))
.Should().Be(FileSystem.File.ReadAllBytes("foo/bar/test.txt"));
}

#if FEATURE_COMPRESSION_STREAM
Expand All @@ -170,16 +169,16 @@ public async Task CreateFromDirectory_WithReadOnlyStream_ShouldThrowArgumentExce
using FileSystemStream stream = FileSystem.FileStream.New(
"target.zip", FileMode.Open, FileAccess.Read);

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

exception.Should().BeException<ArgumentException>(
paramName: "destination",
hResult: -2147024809,
messageContains: "stream is unwritable");
await That(Act).Should().Throw<ArgumentException>()
.WithParamName("destination").And
.WithHResult(-2147024809).And
.WithMessage("*stream is unwritable*").AsWildcard();
}
#endif

Expand All @@ -200,8 +199,8 @@ public async Task

using IZipArchive archive = FileSystem.ZipArchive().New(stream, ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("bar/"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("bar/"));
}
#endif

Expand All @@ -220,7 +219,7 @@ public async Task CreateFromDirectory_WithStream_EmptySource_DoNotIncludeBaseDir

using IZipArchive archive = FileSystem.ZipArchive().New(stream, ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(0);
await That(archive.Entries).Should().BeEmpty();
}
#endif

Expand All @@ -240,8 +239,8 @@ public async Task

using IZipArchive archive = FileSystem.ZipArchive().New(stream, ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("foo/"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("foo/"));
}
#endif

Expand All @@ -262,14 +261,14 @@ public async Task CreateFromDirectory_WithStream_EntryNameEncoding_ShouldUseEnco

using IZipArchive archive = FileSystem.ZipArchive().New(stream, ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
var singleEntry = await That(archive.Entries).Should().HaveSingle();
if (encodedCorrectly)
{
archive.Entries.Should().Contain(e => e.Name == entryName);
await That(singleEntry.Name).Should().Be(entryName);
}
else
{
archive.Entries.Should().NotContain(e => e.Name == entryName);
await That(singleEntry.Name).Should().NotBe(entryName);
}
}
#endif
Expand All @@ -290,8 +289,8 @@ public async Task CreateFromDirectory_WithStream_IncludeBaseDirectory_ShouldPrep

using IZipArchive archive = FileSystem.ZipArchive().New(stream, ZipArchiveMode.Read);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("foo/test.txt"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("foo/test.txt"));
}
#endif

Expand All @@ -302,13 +301,15 @@ public async Task
{
Stream stream = new MemoryStreamMock(canWrite: false);

Exception? exception = Record.Exception(() =>
void Act()
{
FileSystem.ZipFile().CreateFromDirectory("foo", stream);
});
}

exception.Should().BeException<ArgumentException>("The stream is unwritable",
paramName: "destination", hResult: -2147024809);
await That(Act).Should().Throw<ArgumentException>()
.WithMessage("The stream is unwritable").And
.WithParamName("destination").And
.WithHResult(-2147024809);
}
#endif

Expand All @@ -319,13 +320,13 @@ public async Task
{
Stream stream = null!;

Exception? exception = Record.Exception(() =>
void Act()
{
FileSystem.ZipFile().CreateFromDirectory("foo", stream);
});
}

exception.Should().BeOfType<ArgumentNullException>()
.Which.ParamName.Should().Be("destination");
await That(Act).Should().Throw<ArgumentNullException>()
.WithParamName("destination");
}
#endif

Expand All @@ -350,8 +351,8 @@ public async Task CreateFromDirectory_WithStream_Overwrite_WithEncoding_ShouldOv
IZipArchive archive =
FileSystem.ZipArchive().New(stream, ZipArchiveMode.Read, true, encoding);

archive.Entries.Count.Should().Be(1);
archive.Entries.Should().Contain(e => e.FullName.Equals("test.txt"));
await That(archive.Entries).Should().HaveSingle()
.Which.For(x => x.FullName, f => f.Should().Be("test.txt"));
}
#endif

Expand All @@ -370,11 +371,9 @@ public async Task CreateFromDirectory_WithStream_ShouldZipDirectoryContent()

FileSystem.ZipFile().ExtractToDirectory(stream, "destination");

FileSystem.File.Exists("destination/bar/test.txt")
.Should().BeTrue();
FileSystem.File.ReadAllBytes("destination/bar/test.txt")
.Should().BeEquivalentTo(
FileSystem.File.ReadAllBytes("foo/bar/test.txt"));
await That(FileSystem).Should().HaveFile("destination/bar/test.txt");
await That(FileSystem.File.ReadAllBytes("destination/bar/test.txt"))
.Should().Be(FileSystem.File.ReadAllBytes("foo/bar/test.txt"));
}
#endif

Expand Down
Loading
Loading