pact-foundation / pact-net

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
846 stars 234 forks source link

ClearInteraction when using messaging pacts #479

Closed singhvivek2503 closed 1 year ago

singhvivek2503 commented 1 year ago

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

this.pact = Pact.V4("ConsumerName", "ProviderName", config)
                .WithMessageInteractions();
mefellows commented 1 year ago

Why do you think you need to clear them?

singhvivek2503 commented 1 year ago

Why do you need to clear them?

Writing updated versions of old tests and adding new tests. The contract json file preserves the older interactions which I don't need anymore.

mefellows commented 1 year ago

Why does that matter? You shouldn't be uploading from a dirty development environment anyway.

If you need to clear old interactions, just delete the file

singhvivek2503 commented 1 year ago

Why does that matter? You shouldn't be uploading from a dirty development environment anyway.

If you need to clear old interactions, just delete the file

Ok. Wondering if that's correct, why its there in here _mockProviderServiceInstance.ClearInteractions()?

adamrodger commented 1 year ago

The ClearInteractions method was removed from PactNet in v4.x and is no longer required.

As @mefellows says, you should be starting each test run from a fresh environment with no existing Pact file so that older interactions aren't left behind.