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 232 forks source link

Examples from Samples directory do not work out of the box #399

Closed MaciejReszotnik closed 2 years ago

MaciejReszotnik commented 2 years ago

When trying to run Sample project "Messaging" and "Readme" I encountered an issue. I ran those on Windows 10.

After running 'dotnet restore' command on 'consumer' and 'consumer.tests' projects when I try to run the tests - be it with 'dotnet test' or via runner in Visual Studio I get the following error:

C:\Program Files\dotnet\sdk\6.0.300\Microsoft.Common.CurrentVersion.targets(5097,5): error MSB3030: Could not copy the file "C:\pact3\pact-net\build\windows\x86_64\pact_ffi.dll" because it was not found. [C:\pact3\pact-net\src\PactNet\Pac tNet.csproj]

Obviously, if you follow the 'C:\pact3\pact-net\build\windows\x86_64\pact_ffi.dll' path the files is indeed not there - there is no windows folder.

I tried 'dotnet build' again Consumer.tests project - same issue.

One other thing I noticed while inspecting Nuget packages in Visual Studio is that I can see that PactNet is not listed as installed.

Installing official stable version PactNet 3.0.2 and PactNetWindows does not fix the problem. How to solve this?

MaciejReszotnik commented 2 years ago

To answer my own question. It seems to me the creator assumed it was abvious to add pact_ffi.dll from external source and then attempt to run the project. This makes sense for PactNet itself, to avoid version management hassle and decouple it from external project.

However, I think most people are used to the fact that - at least for sample projects - all required files are downloaded once you restore it or run things like package managers.

For these examples a simple quick fix is to substitute Project Reference to non-existing project with PackageReference. In first ItemGroup section add <PackageReference Include="PactNet" Version="4.0.0-beta.5" /> entry. From second ItemGroup section delete or comment out entry

<ProjectReference Include="..\..\..\src\PactNet\PactNet.csproj" />

For example for Messaging project one has to make following changes in Consumer.Tests.csproj:

`

net6.0 false all runtime; build; native; contentfiles; analyzers; buildtransitive **** ****

`

Similar change must be made in Provider.Tests.csproj file.

I suggest that either a detailed explanation was created how to set up those sample test projects to be able to run them - perhaps in a README file. Alternatively the package references could be added as shown in code excerpt above.

adamrodger commented 2 years ago

You have to run the script from the build folder which gets the correct FFI libraries for you, like the CI does.

It has to be done this way because different branches could be using different versions, and I don't want to check in hundreds of MBs of FFI binaries.