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
823 stars 225 forks source link

ClearInteraction when using messaging pacts #479

Closed singhvivek2503 closed 8 months ago

singhvivek2503 commented 8 months 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 8 months ago

Why do you think you need to clear them?

singhvivek2503 commented 8 months 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 8 months 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 8 months 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 8 months 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.