-
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.
- Loading branch information
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
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(); | ||
} | ||
|
||
public class DummyZipArchiveEntry( | ||
IFileSystem fileSystem, | ||
IZipArchive? archive = null, | ||
string? fullName = "", | ||
string? name = "", | ||
string comment = "", | ||
bool isEncrypted = false, | ||
Check warning on line 45 in Tests/Testably.Abstractions.Compression.Tests/Internal/ZipUtilitiesTests.cs Codacy Production / Codacy Static Code AnalysisTests/Testably.Abstractions.Compression.Tests/Internal/ZipUtilitiesTests.cs#L45
Check notice on line 45 in Tests/Testably.Abstractions.Compression.Tests/Internal/ZipUtilitiesTests.cs Codacy Production / Codacy Static Code AnalysisTests/Testably.Abstractions.Compression.Tests/Internal/ZipUtilitiesTests.cs#L45
|
||
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 | ||
} | ||
} |