Search code examples
c#.net-6.0pactpact-net

How to ClearInteractions when using messaging pacts


I am using messaging pacts to contract test event based communication. Is there a way to clear contract json interactions similar to _mockProviderServiceInstance.ClearInteractions() when using messaging pacts?

this.pact = Pact.V4("ConsumerName", "ProviderName", config)
                .WithMessageInteractions();

Solution

  • As discussed here, that is a method that is available in 3.x due to the way the lifecycling of the contracts was managed. It is not necessary to be used in the latest version (4.x, and the 5.x beta as of this post) of Pact .NET.

    You should be starting each test run from a fresh environment with no existing pact file so that older interactions aren't left behind. In a development environment, this is not usually a problem anyway because the contract file is a transient thing. Publishing of contracts should happen from a controlled environment, such as CI.

    If you need to clear out the contents of the pact file, just delete it.