McVerifier 1.0.3
dotnet add package McVerifier --version 1.0.3
NuGet\Install-Package McVerifier -Version 1.0.3
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="McVerifier" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add McVerifier --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: McVerifier, 1.0.3"
#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.
// Install McVerifier as a Cake Addin #addin nuget:?package=McVerifier&version=1.0.3 // Install McVerifier as a Cake Tool #tool nuget:?package=McVerifier&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Microservices message contract verifier .net
This is verification contract library. It provides implementations that make it possible to run Message contract testing in event-driven microservice architecture.
- It verify message schema and prevent unexpected changes.
- It verify producer message using concumers contracts.
Why Use This Library?
- It removes dependencies between microservices while using asynchronous events communication and keep contracts consistence.
- Not need to use shared nuget packages or git submodules with message types which bring dependencies between microservices.
- You can be sure that your messages contracts valid between microservices.
- You notified about the issue during pipelines run and not after you update a nuget package.
How it works
<img src="https://github.com/khdevnet/mc-verifier/blob/master/docs/how-it-workds.png" width="550">
Getting started
Consumer project
- Install the NJsonSchema nuget package
- Create message and add constraints
public class UserCreatedEvent
{
[Required]
[Range(0, 10)]
public int? Id { get; set; }
}
Consumer contracts verification project
- Create a new Xunit test project Consumer1.ContractTests example
- Install the McVerifier nuget package
- Install the ApprovalTests nuget package
- Create test class
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
using McVerifier;
using McVerifier.Utils;
using System.IO;
using Xunit;
namespace Consumer1.ContractTests;
[UseApprovalSubdirectory("Approvals")]
[UseReporter(typeof(VisualStudioReporter))]
public class Schemas
{
[Fact]
public void UserCreatedEvent()
{
// Folder where generated json schema contract file will be save.
var contractsFolder = Path.Combine(
FileUtils.GetSolutionDirectory(),
"ConsumerContracts//Consumer1");
MessageSchema
.Create(typeof(UserCreatedEvent))
.Verify() // Verify message json schema using ApprovalTests
.Save(contractsFolder); // if verification successful then save schema
}
}
Producer project
- Install the NJsonSchema nuget package
- Create message and add constraints
public class UserCreatedEvent
{
[Required]
[Range(0, 10)]
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
[Range(0, 10)]
public decimal Price { get; set; }
}
Producer contracts verification project
- Create a new Xunit test project Producer.ContractTests example
- Install the McVerifier nuget package
- Install the ApprovalTests nuget package
- Create test class
using McVerifier;
using McVerifier.Abstractions.Loggers;
using McVerifier.Utils;
using System.IO;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace Producer.ContractTests;
public class ProducerContracts
{
private const string ConsumerContracts = "ConsumerContracts";
private readonly ITestOutputHelper _logger;
public ProducerContracts(ITestOutputHelper logger)
=> _logger = logger;
[Fact]
public async Task Verify()
{
// Consumers message contracts root folder
var messagesSchemaRootFolder = Path.Combine(
FileUtils.GetSolutionDirectory(),
ConsumerContracts);
// verify producer message types using consumers contracts
await MessageTypesApprovals
.Create(new SchemaVerifierTestOutputLogger(_logger))
.Verify(messagesSchemaRootFolder, "^Producer.*Event$", "^Producer.*Command$");
}
}
public class SchemaVerifierTestOutputLogger : IMessageVerifierTestOutputLogger
{
private readonly ITestOutputHelper _logger;
public SchemaVerifierTestOutputLogger(ITestOutputHelper logger)
=> _logger = logger;
public void Log(string message) => _logger.WriteLine(message);
}
How to run example
- Run Consumer1.ContractTests and Consumer2.ContractTests
- Contracts will be save to ConsumerContracts folder
- Run Producer.ContractTests
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- ApprovalTests (>= 5.7.2)
- FluentAssertions (>= 6.5.1)
- JsonSchema.Net.Data (>= 1.0.5)
- JsonSchema.Net.DataGeneration (>= 0.1.1)
- NJsonSchema (>= 10.6.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.