Pact.Provider.Wrapper 1.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pact.Provider.Wrapper --version 1.4.0
                    
NuGet\Install-Package Pact.Provider.Wrapper -Version 1.4.0
                    
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="Pact.Provider.Wrapper" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pact.Provider.Wrapper" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Pact.Provider.Wrapper" />
                    
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 Pact.Provider.Wrapper --version 1.4.0
                    
#r "nuget: Pact.Provider.Wrapper, 1.4.0"
                    
#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.
#addin nuget:?package=Pact.Provider.Wrapper&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Pact.Provider.Wrapper&version=1.4.0
                    
Install as a Cake Tool

About

In my use cases of Pactnet, i needed to perform broker related tasks in different jobs in cicd, i also wanted to be able to connect PactNet to my own broker. There fore there was some code repeating across all my projects that i preferred to have them as a separate package. And here it is.

This library

  • Merges all available Pact files
  • Performs tests per each interaction
  • Publishes the results for each Endpoint.
    • Each request path, is considered an api endpoint, it may have one or more interactions.
    • The result of testing an endpoint, is successful when all interaction tests towards this endpoint is passed.
  • Publishers are extendable, the package also contains an Html publisher which produces an html file presenting the results.

In my case, i publish the results to a badge server and i use these badges in my api wiki, so any team member can have see the state of implementation of apis at the api wiki.

Important Note
pact-net package wraps the ruby version of pact and when using it and you need to reference its package regarding the platform your tests are running at. So for example
in my case, which i run my tests on a 64 bit linux, i add <PackageReference Include="PactNet.Linux.x64" Version="3.0.0" /> reference alongside the <PackageReference Include="Pact.Provider.Wrapper" /> reference in my csproj file (or via package manager and etc.). Other platforms can be PactNet.Windows, PactNet.Linux.x86 and PactNet.OSX

Examples

Without publishing the results

   // Unit test method based on exceptions like xUnit (with [Fact] attribute or NUnit or etc...
   public void Providers_GivenPacts_ShouldHonorAllPacts(){
       // settup your application
       var app = SetupApp();
       // Start api service(s)
       app.Start();
       // Create test bench
       // This example assumes your services would be up at http://localhost:9222 
       var bench = new PactVerificationBench("http://localhost:9222");
       // Assuming the test projects executable is built at 
       // <project-directory>/bin/<configuration>/<sdk>/<executable>
       // for example: Example.Pact.Test/bin/Debug/netcoreapp3.1/Example.Pact.Test
       bench.Verify("../../../../Pacts");
       // Stop api service(s)
       app.StopAsync().Wait();
   }

With Original Pact broker

   // Unit test method based on exceptions like xUnit (with [Fact] attribute or NUnit or etc...
   public void Providers_GivenPacts_ShouldHonorAllPacts(){
       // settup your application
       var app = SetupApp();
       // Start api service(s)
       app.Start();
       // Create test bench
       // This example assumes your services would be up at http://localhost:9222 
       var bench = new PactVerificationBench("http://localhost:9222");
       // >>>>>>>>>>>>>>>>>>>>>>
       // Use DefaultPactnetVerificationPublish which makes test bench use the
       // Original Pact broker for publishing results besed on _links data. 
       bench.PactnetVerificationPublish = new DefaultPactnetBrokerPublish();
       // Assuming the test projects executable is built at 
       // <project-directory>/bin/<configuration>/<sdk>/<executable>
       // for example: Example.Pact.Test/bin/Debug/netcoreapp3.1/Example.Pact.Test
       bench.Verify("../../../../Pacts");
       // Stop api service(s)
       app.StopAsync().Wait();
   }

Use Html Publisher

   // Unit test method based on exceptions like xUnit (with [Fact] attribute or NUnit or etc...
   public void Providers_GivenPacts_ShouldHonorAllPacts(){
       // settup your application
       var app = SetupApp();
       // Start api service(s)
       app.Start();
       // Create test bench
       // This example assumes your services would be up at http://localhost:9222 
       var bench = new PactVerificationBench("http://localhost:9222");
       // >>>>>>>>>>>>>>>>>>>>>>
       // With this line, an html file named Report.html will be generated where 
       // your executable file is placed. The filename argument can point to any 
       // other address you prefer. 
       bench.WithPublishers()
                       .Add(new HtmlReportVerificationPublisher("Report.html"))
       // Assuming the test projects executable is built at 
       // <project-directory>/bin/<configuration>/<sdk>/<executable>
       // for example: Example.Pact.Test/bin/Debug/netcoreapp3.1/Example.Pact.Test
       bench.Verify("../../../../Pacts");
       // Stop api service(s)
       app.StopAsync().Wait();
   }

Use a Custom Publisher

You can implement the interface IVerificationPublisher, and use it for publishing verification results. I have my own implementation named: AcidmanicPactBrokerPublisher, which takes an address and a token in its constructor. Where the address points to where I host my broker. my broker Also needs a token to communicate, which is also passed to the constructor.

(In real case scenario, to prevent putting passwords in code, i take it from environment variables, which is useful when you are running your tests in cicd pipelines)

    // Unit test method based on exceptions like xUnit (with [Fact] attribute or NUnit or etc...
    public void Providers_GivenPacts_ShouldHonorAllPacts(){
        // settup your application
        var app = SetupApp();
        // Start api service(s)
        app.Start();
        // Create test bench
        // This example assumes your services would be up at http://localhost:9222 
        var bench = new PactVerificationBench("http://localhost:9222");
        // In this example the class YourCustomPactBrokerPublisher, is an implementation
        // of the interface IVerificationPublisher
        bench.WithPublishers().Add(new YourCustomPactBrokerPublisher());
        // Assuming the test projects executable is built at 
        // <project-directory>/bin/<configuration>/<sdk>/<executable>
        // for example: Example.Pact.Test/bin/Debug/netcoreapp3.1/Example.Pact.Test
        bench.Verify("../../../../Pacts");
        // Stop api service(s)
        app.StopAsync().Wait();
    }

You can also use multiple Publishers together by calling the Add method in a fluent syntax fashion.

    bench.WithPublishers()
                .Add(new HtmlReportVerificationPublisher("Report.html"))
                .Add(new YourCustomPactBrokerPublisher());

That's about it. I hope it helps saving your time.

Other Feature

  • Run Tests Separately
  • Use Matchers
  • Register Request Filters

More Details

For More detailed version of this readme file, please refer to Github Page for this project.

Updates

You can trace changes and updates log in Change log Document.

Regards.

Mani.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

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.6.6 396 11/30/2022
1.6.5 460 10/19/2022
1.6.4 579 9/14/2022
1.6.3 555 3/7/2022
1.6.2 370 12/12/2021
1.6.1 354 11/29/2021
1.5.8 351 11/28/2021
1.5.5 387 8/9/2021
1.5.4 391 7/24/2021
1.5.3 488 7/12/2021
1.5.2 428 7/7/2021
1.5.1 431 6/29/2021
1.5.0 435 6/29/2021
1.4.1 424 6/28/2021
1.4.0 373 6/28/2021
1.3.2 450 6/14/2021
1.3.1 442 6/13/2021
1.3.0 437 6/11/2021
1.2.0 404 6/4/2021
1.1.1 398 6/3/2021
1.1.0 382 6/2/2021
1.0.0 425 5/18/2021