Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use aweXpect for Compression project #685

Merged
merged 1 commit into from
Dec 16, 2024
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
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<ItemGroup>
<PackageVersion Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
<PackageVersion Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageVersion Include="aweXpect" Version="0.7.0" />
<PackageVersion Include="aweXpect" Version="0.10.0" />
<PackageVersion Include="aweXpect.Testably" Version="0.2.0" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Xunit.SkippableFact" Version="1.5.23" />
Expand Down
1 change: 1 addition & 0 deletions Tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<ItemGroup>
<PackageReference Include="aweXpect" />
<PackageReference Include="aweXpect.Testably" />
<PackageReference Include="AutoFixture.Xunit2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Xunit.SkippableFact" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Testably.Abstractions.Compression.Tests.Internal;
public sealed class ExecuteTests
{
[Fact]
public void WhenRealFileSystem_MockFileSystem_WithActionCallback_ShouldExecuteOnMockFileSystem()
public async Task WhenRealFileSystem_MockFileSystem_WithActionCallback_ShouldExecuteOnMockFileSystem()
{
bool onRealFileSystemExecuted = false;
bool onMockFileSystemExecuted = false;
Expand All @@ -20,12 +20,12 @@ public void WhenRealFileSystem_MockFileSystem_WithActionCallback_ShouldExecuteOn
onMockFileSystemExecuted = true;
});

onRealFileSystemExecuted.Should().BeFalse();
onMockFileSystemExecuted.Should().BeTrue();
await That(onRealFileSystemExecuted).Should().BeFalse();
await That(onMockFileSystemExecuted).Should().BeTrue();
}

[Fact]
public void WhenRealFileSystem_MockFileSystem_WithFuncCallback_ShouldExecuteOnMockFileSystem()
public async Task WhenRealFileSystem_MockFileSystem_WithFuncCallback_ShouldExecuteOnMockFileSystem()
{
bool onRealFileSystemExecuted = false;
bool onMockFileSystemExecuted = false;
Expand All @@ -40,12 +40,12 @@ public void WhenRealFileSystem_MockFileSystem_WithFuncCallback_ShouldExecuteOnMo
return onMockFileSystemExecuted = true;
});

onRealFileSystemExecuted.Should().BeFalse();
onMockFileSystemExecuted.Should().BeTrue();
await That(onRealFileSystemExecuted).Should().BeFalse();
await That(onMockFileSystemExecuted).Should().BeTrue();
}

[Fact]
public void WhenRealFileSystem_RealFileSystem_WithActionCallback_ShouldExecuteOnRealFileSystem()
public async Task WhenRealFileSystem_RealFileSystem_WithActionCallback_ShouldExecuteOnRealFileSystem()
{
bool onRealFileSystemExecuted = false;
bool onMockFileSystemExecuted = false;
Expand All @@ -60,12 +60,12 @@ public void WhenRealFileSystem_RealFileSystem_WithActionCallback_ShouldExecuteOn
onMockFileSystemExecuted = true;
});

onRealFileSystemExecuted.Should().BeTrue();
onMockFileSystemExecuted.Should().BeFalse();
await That(onRealFileSystemExecuted).Should().BeTrue();
await That(onMockFileSystemExecuted).Should().BeFalse();
}

[Fact]
public void WhenRealFileSystem_RealFileSystem_WithFuncCallback_ShouldExecuteOnRealFileSystem()
public async Task WhenRealFileSystem_RealFileSystem_WithFuncCallback_ShouldExecuteOnRealFileSystem()
{
bool onRealFileSystemExecuted = false;
bool onMockFileSystemExecuted = false;
Expand All @@ -80,7 +80,7 @@ public void WhenRealFileSystem_RealFileSystem_WithFuncCallback_ShouldExecuteOnRe
return onMockFileSystemExecuted = true;
});

onRealFileSystemExecuted.Should().BeTrue();
onMockFileSystemExecuted.Should().BeFalse();
await That(onRealFileSystemExecuted).Should().BeTrue();
await That(onMockFileSystemExecuted).Should().BeFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ public sealed class ZipUtilitiesTests
{
[Theory]
[AutoData]
public void ExtractRelativeToDirectory_FileWithTrailingSlash_ShouldThrowIOException(
public async Task ExtractRelativeToDirectory_FileWithTrailingSlash_ShouldThrowIOException(
byte[] bytes)
{
MockFileSystem fileSystem = new();
using MemoryStream stream = new(bytes);
DummyZipArchiveEntry zipArchiveEntry = new(fileSystem, fullName: "foo/", stream: stream);

Exception? exception = Record.Exception(() =>
void Act()
{
zipArchiveEntry.ExtractRelativeToDirectory("foo", false);
});
}

exception.Should().BeException<IOException>(
messageContains:
"Zip entry name ends in directory separator character but contains data");
await That(Act).Should().Throw<IOException>()
.WithMessage("*Zip entry name ends in directory separator character but contains data*")
.AsWildcard();
}

[Fact]
public void ExtractRelativeToDirectory_WithSubdirectory_ShouldCreateSubdirectory()
public async Task ExtractRelativeToDirectory_WithSubdirectory_ShouldCreateSubdirectory()
{
MockFileSystem fileSystem = new();
DummyZipArchiveEntry zipArchiveEntry = new(fileSystem, fullName: "foo/");

zipArchiveEntry.ExtractRelativeToDirectory("bar", false);

fileSystem.Directory.Exists("bar").Should().BeTrue();
fileSystem.Directory.Exists("bar/foo").Should().BeTrue();
await That(fileSystem).Should().HaveDirectory("bar");
await That(fileSystem).Should().HaveDirectory("bar/foo");
}

private sealed class DummyZipArchiveEntry(
Expand All @@ -46,17 +46,14 @@ private sealed class DummyZipArchiveEntry(
Stream? stream = null)
: IZipArchiveEntry
{
/// <inheritdoc cref="IZipArchiveEntry.Comment" />
public string Comment { get; set; } = comment;

/// <inheritdoc cref="IZipArchiveEntry.IsEncrypted" />
public bool IsEncrypted { get; } = isEncrypted;

#region IZipArchiveEntry Members

/// <inheritdoc cref="IZipArchiveEntry.Archive" />
public IZipArchive Archive => archive ?? throw new NotSupportedException();

/// <inheritdoc cref="IZipArchiveEntry.Comment" />
public string Comment { get; set; } = comment;

/// <inheritdoc cref="IZipArchiveEntry.CompressedLength" />
public long CompressedLength => stream?.Length ?? 0L;

Expand All @@ -72,6 +69,9 @@ private sealed class DummyZipArchiveEntry(
/// <inheritdoc cref="IZipArchiveEntry.FullName" />
public string FullName { get; } = fullName ?? "";

/// <inheritdoc cref="IZipArchiveEntry.IsEncrypted" />
public bool IsEncrypted { get; } = isEncrypted;

/// <inheritdoc cref="IZipArchiveEntry.LastWriteTime" />
public DateTimeOffset LastWriteTime { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
global using AutoFixture.Xunit2;
global using FluentAssertions;
global using System;
global using System.Threading.Tasks;
global using System.IO.Abstractions;
global using Testably.Abstractions.TestHelpers;
global using Testably.Abstractions.Testing;
global using Xunit;
global using aweXpect;
global using aweXpect.Testably;
global using static aweXpect.Expect;
Loading
Loading