PQSoft.JsonComparer.AwesomeAssertions
1.0.0-alpha11
This is a prerelease version of PQSoft.JsonComparer.AwesomeAssertions.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PQSoft.JsonComparer.AwesomeAssertions --version 1.0.0-alpha11
NuGet\Install-Package PQSoft.JsonComparer.AwesomeAssertions -Version 1.0.0-alpha11
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PQSoft.JsonComparer.AwesomeAssertions" Version="1.0.0-alpha11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PQSoft.JsonComparer.AwesomeAssertions" Version="1.0.0-alpha11" />
<PackageReference Include="PQSoft.JsonComparer.AwesomeAssertions" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PQSoft.JsonComparer.AwesomeAssertions --version 1.0.0-alpha11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PQSoft.JsonComparer.AwesomeAssertions, 1.0.0-alpha11"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PQSoft.JsonComparer.AwesomeAssertions@1.0.0-alpha11
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PQSoft.JsonComparer.AwesomeAssertions&version=1.0.0-alpha11&prerelease
#tool nuget:?package=PQSoft.JsonComparer.AwesomeAssertions&version=1.0.0-alpha11&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PQSoft.JsonComparer.AwesomeAssertions
AwesomeAssertions extensions for JSON comparison that integrate seamlessly with the JsonComparer functionality.
Features
- Provides a fluent API for JSON assertions
- Works with the token extraction features of JsonComparer
- Supports both exact match and subset match assertions
- Integrates with AwesomeAssertions failure reporting
Installation
dotnet add package PQSoft.JsonComparer.AwesomeAssertions
Usage
Basic Fluent Assertions
string actualJson = """{ "id": "12345", "name": "John", "status": "active" }""";
string expectedJson = """{ "id": "[[USER_ID]]", "name": "John", "status": "active" }""";
actualJson.AsJsonString().Should().FullyMatch(expectedJson);
// Assertion passes and USER_ID token is extracted
Subset Matching
string actualJson = """{
"id": 123,
"name": "John",
"email": "john@example.com",
"status": "active",
"created": "2024-01-01T10:00:00Z"
}""";
string expectedSubset = """{ "name": "John", "status": "active" }""";
actualJson.AsJsonString().Should().ContainSubset(expectedSubset);
// Passes - actual JSON contains all expected fields
Token Extraction with Assertions
string apiResponse = """{
"orderId": "order_12345",
"userId": "user_67890",
"total": 99.99,
"status": "completed"
}""";
string template = """{
"orderId": "[[ORDER_ID]]",
"userId": "[[USER_ID]]",
"total": "[[TOTAL]]",
"status": "completed"
}""";
var result = apiResponse.AsJsonString().Should().FullyMatch(template);
// Access extracted tokens
var orderId = result.ExtractedTokens["ORDER_ID"]; // "order_12345"
var userId = result.ExtractedTokens["USER_ID"]; // "user_67890"
var total = result.ExtractedTokens["TOTAL"]; // "99.99"
Function-Based Matching
string actualResponse = """{
"id": "550e8400-e29b-41d4-a716-446655440000",
"createdAt": "2024-01-01T10:00:00.000Z",
"processedAt": "2024-01-01T10:05:30.123+00:00"
}""";
string expectedTemplate = """{
"id": "{{GUID()}}",
"createdAt": "{{UTCNOW()}}",
"processedAt": "{{NOW()}}"
}""";
actualResponse.AsJsonString().Should().FullyMatch(expectedTemplate);
// Functions are executed and validated against actual values
Complex API Testing
// Test API response structure and extract values for further testing
string createUserResponse = """{
"user": {
"id": "usr_abc123",
"email": "test@example.com",
"profile": {
"firstName": "John",
"lastName": "Doe"
}
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresAt": "2024-12-31T23:59:59Z"
}""";
string expectedStructure = """{
"user": {
"id": "[[USER_ID]]",
"email": "test@example.com",
"profile": {
"firstName": "John",
"lastName": "Doe"
}
},
"token": "[[AUTH_TOKEN]]",
"expiresAt": "{{UTCNOW()}}"
}""";
var result = createUserResponse.AsJsonString().Should().FullyMatch(expectedStructure);
// Use extracted tokens in subsequent tests
var userId = result.ExtractedTokens["USER_ID"];
var authToken = result.ExtractedTokens["AUTH_TOKEN"];
Error Assertions
string errorResponse = """{ "error": "Invalid request", "code": 400 }""";
string expectedError = """{ "error": "Invalid request", "code": 400 }""";
errorResponse.AsJsonString().Should().FullyMatch(expectedError);
Array and Complex Object Matching
string actualJson = """{
"users": [
{ "id": "1", "name": "John" },
{ "id": "2", "name": "Jane" }
],
"total": 2
}""";
string expectedPattern = """{
"users": [
{ "id": "[[USER1_ID]]", "name": "John" },
{ "id": "[[USER2_ID]]", "name": "Jane" }
],
"total": 2
}""";
var result = actualJson.AsJsonString().Should().FullyMatch(expectedPattern);
// Extracts USER1_ID = "1" and USER2_ID = "2"
Dependencies
This package depends on:
- PQSoft.JsonComparer
- AwesomeAssertions
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- AwesomeAssertions (>= 9.1.0)
- PQSoft.JsonComparer (>= 1.0.0-alpha11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.1.0-beta.3 | 145 | 9/20/2025 |
1.1.0-beta.2 | 161 | 9/19/2025 |
1.1.0-beta.1 | 165 | 9/19/2025 |
1.0.0-beta.6 | 229 | 9/19/2025 |
1.0.0-beta.5 | 225 | 9/19/2025 |
1.0.0-beta.4 | 223 | 9/19/2025 |
1.0.0-beta.3 | 224 | 9/19/2025 |
1.0.0-beta.2 | 225 | 9/19/2025 |
1.0.0-beta.1 | 240 | 9/19/2025 |
1.0.0-alpha9 | 242 | 9/18/2025 |
1.0.0-alpha8 | 243 | 9/18/2025 |
1.0.0-alpha7 | 249 | 9/17/2025 |
1.0.0-alpha5 | 247 | 9/16/2025 |
1.0.0-alpha4 | 250 | 9/16/2025 |
1.0.0-alpha3 | 249 | 9/16/2025 |
1.0.0-alpha2 | 247 | 9/16/2025 |
1.0.0-alpha11 | 244 | 9/19/2025 |
1.0.0-alpha10 | 242 | 9/18/2025 |
1.0.0-alpha1 | 195 | 9/15/2025 |