I spent the whole afternoon to set up the provider...
# documentation
d
I spent the whole afternoon to set up the provider in .net 8. No success! There is so much confusion and the examples are outdated. I need to build a proof of concept to propose it at work but it looks like it is not the case anymore
j
Keeping all the docs up to date is a big effort, and there are quite a few examples. Which example did you have issues with? Have you look at https://github.com/pact-foundation/pact-net? If there's a specific issue within that repo, feel free to raise a ticket in that repository 🙂
m
Thanks Josh. There are also these examples that I believe are on .net 8: https://docs.pactflow.io/docs/examples/dotnet/consumer/
One issue that people seem to get stuck on is this one (from the readme):
If you could elaborate on the confusion, we would be happy to help (and/or update the documentation and examples as necessary)
d
Yes, this one is very confusing as I use a minimal API and there is not an official example to sort this scenario. I had to rely on a GitHub example. It is not ideal. Also, the pact CLI, once I downloaded it ,I had to figure out myself that I needed to set the environment for the bin folder, there is not info about it too. I am confident that pact has great potential but is just lacking these bits of information. At the moment I'm sorting things out with a lot of effort but I love the idea of pact contracts testing.
m
Can you please elaborate on both of these things? For the provider, it kind of doesn't matter how you start it. As long as you can provide Pact the host and port to communicate to it. Not sure what you mean by "set the environment for the bin folder"? Do you mean add it to the
PATH
?
d
Yes add it to the PATH
The host in minimal API is the program class, so shall I just provide that?
m
Sure. The main point is though your tests need to do the following: 1. Configure and stand up your provider (e.g. https://github.com/pact-foundation/pact-net/blob/master/samples/OrdersApi/Provider.Tests/ProviderTests.cs#L32-L38) 2. Start it on a host/port that can be communicated to from other systems on the host (e.g. https://github.com/pact-foundation/pact-net/blob/master/samples/OrdersApi/Provider.Tests/ProviderTests.cs#L40) 3. Run the Pact verifier, telling it how to communicate to the provider (e.g. https://github.com/pact-foundation/pact-net/blob/master/samples/OrdersApi/Provider.Tests/ProviderTests.cs#L69-L78) If you need to support provider states (which you will eventually) then you’ll need to 1. Setup an endpoint to receive them (e.g. https://github.com/pact-foundation/pact-net/blob/master/samples/OrdersApi/Provider.Tests/TestStartup.cs#L27) 2. Tell the verifier where to send the state change requests to (e.g. https://github.com/pact-foundation/pact-net/blob/master/samples/OrdersApi/Provider.Tests/ProviderTests.cs#L76)
i
This still does require a
TestStartup
file to run, I've seen a couple of threads about using process to host the app when testing but there seems to be a lack of documentation on this too
m
What does that "using process" mean (assume I don't know .Net)
i
Apologies, using the Process class in .NET to access process a process running on a machine where a process is a running app. It serves as an alternative to WebHost or WebApplicatonBuilder (which is what I was originally trying). I was trying out an idea suggested in a StackOverflow post: https://stackoverflow.com/questions/77225303/how-do-i-start-initialize-a-net-core-minimal-api-in-a-separate-test-project
I am actually struggling to get that method to work. I'll ask in #C9UTHV2AD to see if anyone has has any success