VOOZH about

URL: https://www.nuget.org/packages/McVerifier/

⇱ NuGet Gallery | McVerifier 1.0.3




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.
<PackageVersion Include="McVerifier" Version="1.0.3" />
 
Directory.Packages.props
<PackageReference Include="McVerifier" />
 
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 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.
#:package McVerifier@1.0.3
 
 
#: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=McVerifier&version=1.0.3
 
Install as a Cake Addin
#tool nuget:?package=McVerifier&version=1.0.3
 
Install as a Cake Tool
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

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

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 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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

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.0.3 819 4/3/2022
1.0.2 984 4/3/2022
1.0.1 998 4/3/2022