Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pact json being overwritten by each test in C# .NET #493

Closed
cetk opened this issue Feb 23, 2024 · 7 comments
Closed

Pact json being overwritten by each test in C# .NET #493

cetk opened this issue Feb 23, 2024 · 7 comments
Labels
triage This issue is yet to be triaged by a maintainer

Comments

@cetk
Copy link

cetk commented Feb 23, 2024

Software versions

  • **Windows OS
  • Consumer Pact library: e.g. PactNet 3.0.0

I'm writing Pact tests as part of a C# .NET application with NUnit test system. I have several functions that each run a Pact test. They overwrite the previous functions pact definition such that my final pact.json only has the last run test. How do I have separate test functions that all append to the pact test?

Steps to reproduce

Provide a repository, gist or reproducable code snippet so that we can test the problem. You may also want to adapt one of the examples in the repository to demonstrate the problem.

Relevent log files

Please ensure you set logging to DEBUG and attach any relevant log files here (or link from a gist).

@mefellows
Copy link
Member

Did you mean to raise the issue over here: https://github.com/pact-foundation/pact-net/

@mefellows mefellows added the triage This issue is yet to be triaged by a maintainer label Feb 23, 2024
@cetk
Copy link
Author

cetk commented Feb 23, 2024

yes

@mefellows mefellows transferred this issue from pact-foundation/pact-go Feb 23, 2024
@mefellows
Copy link
Member

Moving issue to the correct repo.

@mefellows
Copy link
Member

Could you please perhaps demonstrate (via code) how you construct your Pact tests so that we can better understand?

You are also running quite an old version (3.0.0). Probably, you might just need to ensure you're calling the correct lifecycle method to write the pacts to file as you go.

Example: https://github.com/pact-foundation/pact-net/blob/3.0.2/Samples/EventApi/Consumer.Tests/EventsApiConsumerTests.cs.

If you're new to Pact, I'd suggest upgrading to the latest version.

@cetk
Copy link
Author

cetk commented Feb 23, 2024

the example above helps..it does have all tests published in same pact file, but I don't see any specific settings for the same.
Is the latest version supports it ?

@adamrodger
Copy link
Contributor

PactNet 4.x+ (which is the only supported version) works in merge mode only, thus running tests will always add to an existing file instead of overwriting it. This wasn't the case with v3.x and less, which are all unsupported versions now.

@cetk
Copy link
Author

cetk commented Feb 26, 2024

I see the builder has persisting pact file which keeps all interactions in single pact json.
I have got one more question, how do I send request body with object with inner objects for pact test like

_mockProviderService.UponReceiving("a request to create a new event")
.With(new ProviderServiceRequest
{
Method = HttpVerb.Post,
Path = "/events",
Headers = new Dictionary<string, object>
{
{ "Content-Type", "application/json; charset=utf-8" }
},
Body = new
{
eventId,
eventType = "DetailsView",
timestamp = new TimeObject
{
date = "2024-02-25 21:38:57.290"
}
}
})
.WillRespondWith(new ProviderServiceResponse
{
Status = 201
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage This issue is yet to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants