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 core not found in .Net Core XUnit test #144

Closed
andrewcarson opened this issue Mar 25, 2018 · 4 comments
Closed

Pact core not found in .Net Core XUnit test #144

andrewcarson opened this issue Mar 25, 2018 · 4 comments

Comments

@andrewcarson
Copy link

I'm trying to use PactNet in a .Net Core XUnit test, when running "dotnet xunit" I get:

PactNet.PactFailureException : Please install the relevant platform and architecture specific PactNet dependency from Nuget. Based on your current setup you should install 'PactNet.Linux.x64'.

I do have the PactNet.Linux.x64 package added.

I believe this is because Contants.cs uses AppContext.BaseDirectory, which is then used in PactCoreHost.cs as the expected root of the pack core path.

However, when running under XUnit in .Net core, the AppContext.BaseDirectory folder is not the same as the build directory:

AppContext.BaseDirectory: /home/andyc/.nuget/packages/dotnet-xunit/2.3.1/tools/netcoreapp2.0/
Environment.CurrentDirectory: /home/andyc/tmp/t/test/bin/Debug/netcoreapp2.0
pact-linux-x86_64 exists: True

You can reproduce this using the attached project: test.tar.gz

% tar xzf test.tar.gz
% cd test
% dotnet build
% dotnet xunit
Detecting target frameworks in test.csproj...
Building for framework netcoreapp2.0...
  test -> /home/andyc/tmp/test/bin/Debug/netcoreapp2.0/test.dll
Running .NET Core 2.0.5 tests for framework netcoreapp2.0...
xUnit.net Console Runner (64-bit .NET Core 4.6.0.0)
  Discovering: test
  Discovered:  test
  Starting:    test
AppContext.BaseDirectory: /home/andyc/.nuget/packages/dotnet-xunit/2.3.1/tools/netcoreapp2.0/
Environment.CurrentDirectory: /home/andyc/tmp/test/bin/Debug/netcoreapp2.0
pact-linux-x86_64 exists: True
    test.UnitTest1.Test1 [FAIL]
      PactNet.PactFailureException : Please install the relevant platform and architecture specific PactNet dependency from Nuget. Based on your current setup you should install 'PactNet.Linux.x64'.
      Stack Trace:
        C:\projects\pact-net\PactNet\Core\PactCoreHost.cs(59,0): at PactNet.Core.PactCoreHost`1..ctor(T config)
        C:\projects\pact-net\PactNet\Mocks\MockHttpService\Host\RubyHttpHost.cs(23,0): at PactNet.Mocks.MockHttpService.Host.RubyHttpHost..ctor(Uri baseUri, String consumerName, String providerName, PactConfig config, IPAddress host)
        C:\projects\pact-net\PactNet\Mocks\MockHttpService\MockProviderService.cs(42,0): at PactNet.Mocks.MockHttpService.MockProviderService.<>c__DisplayClass12_0.<.ctor>b__0(Uri baseUri)
        C:\projects\pact-net\PactNet\Mocks\MockHttpService\MockProviderService.cs(132,0): at PactNet.Mocks.MockHttpService.MockProviderService.Start()
        C:\projects\pact-net\PactNet\PactBuilder.cs(82,0): at PactNet.PactBuilder.MockService(Int32 port, JsonSerializerSettings jsonSerializerSettings, Boolean enableSsl, IPAddress host)
        /home/andyc/tmp/test/UnitTest1.cs(24,0): at test.UnitTest1.Test1()
  Finished:    test
=== TEST EXECUTION SUMMARY ===
   test  Total: 1, Errors: 0, Failed: 1, Skipped: 0, Time: 0.231s

There was a similar issue for XUnit and ASP.Net MVC

I can think of a couple of fixes:

  1. Make the base path configurable via PactConfig. This would be pretty clunky.
  2. Try probing both AppContext.BaseDirectory and Environment.CurrentDirectory.
  3. Something else... maybe try to find the test assembly location and probe there?

I'm happy to write something and make a pull request if you express a preference...

@neilcampbell
Copy link
Member

Hmm. Yeah that is a tricky one, it definitely did work, I just can't remember if it was in a netcore1.0 scenario.

A PR would be amazing!

I think ideally we want find the test assembly location and probe there. Potentially we could fallback to AppContext.BaseDirectory.

JanLenoch pushed a commit to kontent-ai/management-sdk-net that referenced this issue Apr 13, 2018
@DennisJantos
Copy link

I had the same issue.

I created a fork and changed the PactCoreHost.cs. The following approach worked for me: DennisJantos@e0f6d6b

Is there any update on this issue?

@andrewcarson
Copy link
Author

I have to admit, I started looking at it, but stalled, struggling to get the unit tests working under Linux/.Net Core.

@adamrodger
Copy link
Contributor

I'm pretty sure this is fixed in later versions of .Net Core. Feel free to reopen if not 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants