PQSoft.JsonComparer.AwesomeAssertions 1.1.0-beta.1

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.
dotnet add package PQSoft.JsonComparer.AwesomeAssertions --version 1.1.0-beta.1
                    
NuGet\Install-Package PQSoft.JsonComparer.AwesomeAssertions -Version 1.1.0-beta.1
                    
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.1.0-beta.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PQSoft.JsonComparer.AwesomeAssertions" Version="1.1.0-beta.1" />
                    
Directory.Packages.props
<PackageReference Include="PQSoft.JsonComparer.AwesomeAssertions" />
                    
Project file
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.1.0-beta.1
                    
#r "nuget: PQSoft.JsonComparer.AwesomeAssertions, 1.1.0-beta.1"
                    
#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.1.0-beta.1
                    
#: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.1.0-beta.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=PQSoft.JsonComparer.AwesomeAssertions&version=1.1.0-beta.1&prerelease
                    
Install as a Cake Tool

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 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PQSoft.JsonComparer.AwesomeAssertions:

Package Downloads
PQSoft.ReqNRoll

Reqnroll step definitions for API testing with PQSoft.HttpFile and PQSoft.JsonComparer

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0-beta.4 25 10/22/2025
1.2.0-beta.3 24 10/22/2025
1.2.0-beta.2 23 10/22/2025
1.2.0-beta.1 22 10/22/2025
1.1.0-beta.3 151 9/20/2025
1.1.0-beta.2 164 9/19/2025
1.1.0-beta.1 169 9/19/2025
1.0.0-beta.6 233 9/19/2025
1.0.0-beta.5 229 9/19/2025
1.0.0-beta.4 226 9/19/2025
1.0.0-beta.3 227 9/19/2025
1.0.0-beta.2 230 9/19/2025
1.0.0-beta.1 242 9/19/2025
1.0.0-alpha9 243 9/18/2025
1.0.0-alpha8 246 9/18/2025
1.0.0-alpha7 250 9/17/2025
1.0.0-alpha5 248 9/16/2025
1.0.0-alpha4 254 9/16/2025
1.0.0-alpha3 252 9/16/2025
1.0.0-alpha2 253 9/16/2025
1.0.0-alpha11 245 9/19/2025
1.0.0-alpha10 244 9/18/2025
1.0.0-alpha1 199 9/15/2025