Skip to content

Commit

Permalink
Add byte based VerifyZip (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 26, 2025
1 parent 3a815e8 commit aef59f9
Show file tree
Hide file tree
Showing 55 changed files with 252 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/verify-zip.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Task WithZipFiltered() =>
zipPath,
include: filePath => filePath.FullName.Contains("Doc"));
```
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L191-L199' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipFilterXunitV3' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L195-L203' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipFilterXunitV3' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -48,7 +48,7 @@ public Task VerifyZipWithInfo() =>
zipPath,
info: "the info");
```
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L164-L172' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipWithInfoXunitV3' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L168-L176' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipWithInfoXunitV3' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -72,7 +72,7 @@ public Task VerifyZipWithFileScrubber() =>
}
});
```
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L174-L189' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipWithFileScrubberXunitV3' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L178-L193' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipWithFileScrubberXunitV3' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

This applies to files where the extensions is a known text file as defined by [FileExtensions.IsText](https://github.com/VerifyTests/EmptyFiles#istext).
Expand All @@ -89,5 +89,5 @@ Use `includeStructure: true` to include a file `structure.verified.md` that cont
public Task WithZipAndStructure() =>
VerifyZip(zipPath, includeStructure: true);
```
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L156-L162' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipWithStructureXunitV3' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L160-L166' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyZipWithStructureXunitV3' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CA1822;CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
<Version>28.12.1</Version>
<Version>28.13.0</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
18 changes: 18 additions & 0 deletions src/Verify.Expecto/Verifier_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,22 @@ public static SettingsTask VerifyZip(
var assembly = Assembly.GetCallingAssembly()!;
return Verify(settings, assembly, sourceFile, name, _ => _.VerifyZip(stream, include, info, fileScrubber, includeStructure), true);
}

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public static SettingsTask VerifyZip(
string name,
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false,
[CallerFilePath] string sourceFile = "")
{
var assembly = Assembly.GetCallingAssembly()!;
return Verify(settings, assembly, sourceFile, name, _ => _.VerifyZip(bytes, include, info, fileScrubber, includeStructure), true);
}
}
3 changes: 3 additions & 0 deletions src/Verify.Fixie.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public Task WithZip() =>

#endregion

public Task WithZipBytes() =>
VerifyZip(File.ReadAllBytes(pathToArchive));

#region VerifyZipWithStructureFixie

public Task WithZipAndStructure() =>
Expand Down
14 changes: 14 additions & 0 deletions src/Verify.Fixie/Verifier_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ public static SettingsTask VerifyZip(
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(stream, include, info, fileScrubber, includeStructure), true);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public static SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(bytes, include, info, fileScrubber, includeStructure), true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Another text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
5 changes: 5 additions & 0 deletions src/Verify.MSTest.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public Task WithZip() =>

#endregion

[TestMethod]
public Task WithZipBytes() =>
VerifyZip(File.ReadAllBytes(zipPath));


[TestMethod]
public Task VerifyFileWithRelativePath() =>
VerifyFile("sample.png");
Expand Down
14 changes: 14 additions & 0 deletions src/Verify.MSTest/Verifier_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ public static SettingsTask VerifyZip(
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(stream, include, info, fileScrubber, includeStructure), true);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public static SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(bytes, include, info, fileScrubber, includeStructure), true);
}
14 changes: 14 additions & 0 deletions src/Verify.MSTest/VerifyBase_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ public SettingsTask VerifyZip(
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verifier.VerifyZip(stream, include, settings, info, fileScrubber, includeStructure, sourceFile);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verifier.VerifyZip(bytes, include, settings, info, fileScrubber, includeStructure, sourceFile);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Another text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
4 changes: 4 additions & 0 deletions src/Verify.NUnit.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public Task WithZip() =>

#endregion

[Test]
public Task WithZipBytes() =>
VerifyZip(File.ReadAllBytes(pathToArchive));

#region VerifyZipWithStructureNunit

[Test]
Expand Down
14 changes: 14 additions & 0 deletions src/Verify.NUnit/Verifier_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ public static SettingsTask VerifyZip(
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(stream, include, info, fileScrubber, includeStructure), true);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public static SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(bytes, include, info, fileScrubber, includeStructure), true);
}
20 changes: 20 additions & 0 deletions src/Verify.NUnit/VerifyBase_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,24 @@ public SettingsTask VerifyZip(
fileScrubber,
includeStructure,
sourceFile);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false) =>
Verifier.VerifyZip(
bytes,
include,
settings ?? this.settings,
info,
fileScrubber,
includeStructure,
sourceFile);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Another text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
4 changes: 4 additions & 0 deletions src/Verify.TUnit.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public Task WithZip() =>

#endregion

[Test]
public Task WithZipBytes() =>
VerifyZip(File.ReadAllBytes(pathToArchive));

#region VerifyZipWithStructureTunit

[Test]
Expand Down
14 changes: 14 additions & 0 deletions src/Verify.TUnit/Verifier_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ public static SettingsTask VerifyZip(
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(stream, include, info, fileScrubber, includeStructure), true);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public static SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(bytes, include, info, fileScrubber, includeStructure), true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Another text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
4 changes: 4 additions & 0 deletions src/Verify.Xunit.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public Task WithDirectoryFiltered() =>
public Task WithZip() =>
VerifyZip(zipPath);

[Fact]
public Task WithZipBytes() =>
VerifyZip(File.ReadAllBytes(zipPath));

[Fact]
public Task VerifyZipWithInfo() =>
VerifyZip(
Expand Down
14 changes: 14 additions & 0 deletions src/Verify.Xunit/Verifier_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ public static SettingsTask VerifyZip(
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(stream, include, info, fileScrubber, includeStructure), true);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public static SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false,
[CallerFilePath] string sourceFile = "") =>
Verify(settings, sourceFile, _ => _.VerifyZip(bytes, include, info, fileScrubber, includeStructure), true);
}
20 changes: 20 additions & 0 deletions src/Verify.Xunit/VerifyBase_Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,24 @@ public SettingsTask VerifyZip(
fileScrubber,
includeStructure,
sourceFile);

/// <summary>
/// Verifies the contents of a <see cref="ZipArchive" />
/// </summary>
[Pure]
public SettingsTask VerifyZip(
byte[] bytes,
Func<ZipArchiveEntry, bool>? include = null,
VerifySettings? settings = null,
object? info = null,
FileScrubber? fileScrubber = null,
bool includeStructure = false) =>
Verifier.VerifyZip(
bytes,
include,
settings ?? this.settings,
info,
fileScrubber,
includeStructure,
sourceFile);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Another text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
Loading

0 comments on commit aef59f9

Please sign in to comment.