Does anyone know how to create/write a PactNet verifier test using .NET Core 6+?

464 Views Asked by At

I recently heard about Pact and PactNet and it looks promising for testing micro services. Unfortunately, all of the documentation I can find as of today (11 Sept 2023) is painfully outdated and use libraries, properties, etc that are no longer apart of PactNet. Even the github "example" provided by Pact.io for PactNet is no longer valid (https://github.com/pact-foundation/pact-net). Is PactNet dying on the vine?

It appears that other languages may have better coverage and support but I am hoping we may be able to leverage PactNet for our .net code.

I have been able to generate a consumer pact but I have no idea how to implement the provider side. Can anyone point me to current/valid documentation for using Pact with .NET Core 6+? Or...does anyone have a code example?

One final question...if PactNet is not a viable solution, does anyone have any info on other contract testing frameworks that would work for .NET as well as React?

Thank you!

2

There are 2 best solutions below

1
Matthew Fellows On

The example in here uses dotnet 6: https://github.com/pact-foundation/pact-net/tree/master/samples/OrdersApi/Provider.Tests

Pact .NET is alive and well. It has gone through a significant re-write in the past year or so, hence why many examples still use the previous major version.

Even the github "example" provided by Pact.io for PactNet is no longer valid

Can you please share the example you are referring to for clarity (best to just update your question)?

0
Bas Dijkstra On

Here's a start to brand new workshop material I'm creating. It uses a .NET 6 minimal API for the provider implementation, RestAssured.Net for the provider integration tests and Pact.Net 4.5.0 for the provider-side contract verification.

https://github.com/basdijkstra/introduction-to-contract-testing-dotnet

The contract itself is bogus for now (reused something from another workshop), and there's no matching consumers yet, but it works, as in, when you run the provider verification tests, I can see in the output that the contract is picked up and verified against the running provider. Some interactions pass, others fail.

There's a lot of work to be done still but it might be helpful already. Let me know :)