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

Please share examples with .NET 6 new hosting model without Startup.cs #481

Closed fingers10 closed 8 months ago

fingers10 commented 8 months ago

I'm planning to write PACT provider test. But all the examples mentioned in repo uses Startup.cs hosting model.

My .NET 6+ project is using new hosting model which has only Program.cs and no Startup.cs

Please can anyone share example with new hosting model?

mefellows commented 8 months ago

I don't know .NET enough to tell you how, but the main thing you need to do is start your service so that it is accessible over an HTTP port (e.g. port 80). If you can do that, then that's all that matters.

That is, how you start your service is irrelevant - Pact just communicates with it over HTTP.

basdijkstra commented 8 months ago

You mean you’re using a minimal API rather than the traditional controller-based APIs? I wouldn’t call that new versus old but rather a different design type, but I digress.

I’d like to see if there’s an easy way to do this, too. In my example here: https://github.com/basdijkstra/introduction-to-contract-testing-dotnet/tree/main/AddressProvider I had to wrap my API in a Startup / Program construct to enable adding the Pact service URL and ProviderStateMiddleware in my tests.

If there’s an easier way to do that, I’d love to learn more.

fingers10 commented 8 months ago

@basdijkstra I'm using new hosting model which has only Program.cs. And I'm not using minimal api. I'm using normal controllers. A simple .NET 7 API template with normal controller is what I'm using. I googled and found your example repo before raising issue here. I didnt check the contents inside Startup.cs. Now After checking your Startup.cs I'm wondering why this is needed? Can it be added directly in Program.cs?

adamrodger commented 8 months ago

This is a duplicate of #444