Example Consumer

Source Code

https://github.com/pactflow/example-consumer-dotnet

badge__2_.svg: https://github.com/pactflow/example-consumer-dotnet/actions/workflows/build.yml

pactflow--example--provider--dotnet_pact-verified-brightgreen.svg: https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-provider-readyapi/branches/master/latest-version/can-i-deploy/to-environment/production/badge (latest pact)

pact_not_found-unknown-lightgrey.svg: https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-provider-readyapi/branches/master/latest-version/can-i-deploy/to-environment/production/badge (prod)

This is an example of a dotnet core consumer using Pact to create a consumer driven contract and sharing it via API Hub for Contract Testing.

It is using a private tenant on API Hub for Contract Testing. The latest version of the Example Consumer/Example Provider pact is published here.

The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.

  • Test

    • Run tests (including the pact tests that generate the contract)

    • Publish pacts, tagging the consumer version with the name of the current branch

    • Check if we are safe to deploy to prod (ie. has the pact content been successfully verified)

  • Deploy (only from master)

    • Deploy app (just pretend for the purposes of this example!)

    • Tag the deployed consumer version as 'prod'

Dependencies

Usage

See the API Hub for Contract Testing CI/CD Workshop for further details.

The below commands are designed for a Linux/OSX environment, please translate for use on Windows/PowerShell as necessary:

Please ensure the following environment variables have been exported in the process that you run the tests (generally a terminal):

export PACT_BROKER_TOKEN=<your pactflow read/write token here>
export PACT_BROKER_BASE_URL=https://<your pactflow subdomain>.pactflow.io

Run tests

make restore
make test

Simulating CI

Usually, you would integrate this into a real CI system (such as Buildkite/Jenkins/CircleCI etc., or Travis as this repository is built against).

You can simulate a CI process with the following command:

make fake_ci

Publication date: