-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve mutation score for Compression extensions (#551)
Add tests for missing cases in Compression extensions, detected by Stryker.NET.
- Loading branch information
Showing
5 changed files
with
216 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
Tests/Testably.Abstractions.Compression.Tests/Internal/ZipUtilitiesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.IO; | ||
using Testably.Abstractions.Internal; | ||
|
||
namespace Testably.Abstractions.Compression.Tests.Internal; | ||
|
||
public sealed class ZipUtilitiesTests | ||
{ | ||
[Theory] | ||
[AutoData] | ||
public void 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(() => | ||
{ | ||
zipArchiveEntry.ExtractRelativeToDirectory("foo", false); | ||
}); | ||
|
||
exception.Should().BeException<IOException>( | ||
messageContains: | ||
"Zip entry name ends in directory separator character but contains data"); | ||
} | ||
|
||
[Fact] | ||
public void 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(); | ||
} | ||
|
||
private sealed class DummyZipArchiveEntry( | ||
IFileSystem fileSystem, | ||
IZipArchive? archive = null, | ||
string? fullName = "", | ||
string? name = "", | ||
string comment = "", | ||
bool isEncrypted = false, | ||
Stream? stream = null) | ||
: IZipArchiveEntry | ||
{ | ||
#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; | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.Crc32" /> | ||
public uint Crc32 => 0u; | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.ExternalAttributes" /> | ||
public int ExternalAttributes { get; set; } | ||
|
||
/// <inheritdoc cref="IFileSystemEntity.FileSystem" /> | ||
public IFileSystem FileSystem { get; } = fileSystem; | ||
|
||
/// <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; } | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.Length" /> | ||
public long Length => stream?.Length ?? 0L; | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.Name" /> | ||
public string Name { get; } = name ?? ""; | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.Delete()" /> | ||
public void Delete() | ||
=> throw new NotSupportedException(); | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.ExtractToFile(string)" /> | ||
public void ExtractToFile(string destinationFileName) | ||
=> throw new NotSupportedException(); | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.ExtractToFile(string, bool)" /> | ||
public void ExtractToFile(string destinationFileName, bool overwrite) | ||
=> throw new NotSupportedException(); | ||
|
||
/// <inheritdoc cref="IZipArchiveEntry.Open()" /> | ||
public Stream Open() | ||
=> stream ?? throw new NotSupportedException(); | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters