Hello there, I am attempting to run my consumer and provider tests in an Azure Pipeline using an ubuntu agent with Azure tasks. I am able to run the tests fine in my local machine on Windows. However, whenever I switch my PactNet Nuget package to Linux64, and build/run my tests projects, I encounter a failure in my provider test with the following message:
```Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.164.0
Author : Microsoft Corporation
Help :
https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
/usr/bin/dotnet test /home/vsts/work/1/s/pact/Provider/tests --logger trx --results-directory /home/vsts/work/_temp
Test run for /home/vsts/work/1/s/pact/Provider/tests/bin/Debug/net472/tests.dll(.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[
http://xUnit.net 00:00:02.69] tests.ProviderApiTests.EnsureProviderApiHonoursPactWithConsumer [FAIL]
X tests.ProviderApiTests.EnsureProviderApiHonoursPactWithConsumer [274ms]
Error Message:
System.TypeInitializationException : The type initializer for 'PactNet.Constants' threw an exception.
---- System.UriFormatException : Invalid URI: The format of the URI could not be determined.
Stack Trace:
at PactNet.PactVerifier+<>c.<.ctor>b__47_0 (PactNet.Core.PactVerifierHostConfig hostConfig) [0x00000] in <24e08d8a874b4357a3f70f66dbe375e6>:0
at PactNet.PactVerifier.Verify (System.String description, System.String providerState) [0x0010b] in <24e08d8a874b4357a3f70f66dbe375e6>:0
at tests.ProviderApiTests.EnsureProviderApiHonoursPactWithConsumer () [0x000a4] in <37a774785b2a4ef3a32cbac10560f0ad>:0
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <c453bf849bb84e719dbec0475e99db95>:0
----- Inner Stack Trace -----
at System.Uri.CreateThis (System.String uri, System.Boolean dontEscape, System.UriKind uriKind) [0x0007b] in <4d8f95b7df544b3fa1a27dda924b4424>:0
at System.Uri..ctor (System.String uriString) [0x00014] in <4d8f95b7df544b3fa1a27dda924b4424>:0
at PactNet.Constants..cctor () [0x0001e] in <24e08d8a874b4357a3f70f66dbe375e6>:0 ```
All my tasks (Nuget restore, dotnet run/test) are running fine, and my consumer tests are passing. One thing to note, not sure if relevant, is the fact that I targeted different frameworks for my consumer proj (netcoreapp 2.1) and provider proj (net 472). Below is my code for my provider test class:
```
using System;
using System.Collections.Generic;
using PactNet;
using PactNet.Infrastructure.Outputters;
using Xunit;
using Xunit.Abstractions;
using Microsoft.Owin.Hosting;
using tests.XUnitHelpers;
namespace tests
{
public class ProviderApiTests: IDisposable
{
private string _serviceUri { get; }
private string _providerUri { get; }
//private string _pactServiceUri { get; }
private readonly ITestOutputHelper _output;
public ProviderApiTests(ITestOutputHelper output)
{
_output = output;
_providerUri = "
http://52.142.17.145:4000";
_serviceUri = "
http://localhost:9001";
}
[Fact]
public void EnsureProviderApiHonoursPactWithConsumer()
{
//Arrange
const string serviceUri = "
http://localhost:9001";
// var buildNumber = Environment.GetEnvironmentVariable("BUILD_NUMBER");
DateTime utcDate = DateTime.UtcNow;
var buildNumber = utcDate.ToString();
var config = new PactVerifierConfig
{
ProviderVersion = !string.IsNullOrEmpty(buildNumber) ? buildNumber : null, //NOTE: This is required for this feature to work
PublishVerificationResults = !string.IsNullOrEmpty(buildNumber),
Outputters = new List<IOutput>
{
new XUnitOutput(_output)
}
};
using (WebApp.Start<TestStartup>(serviceUri))
{
//Act / Assert
IPactVerifier pactVerifier = new PactVerifier(config);
pactVerifier.ProviderState($"{serviceUri}/provider-states")
.ServiceProvider("TaxonomyGraphQLProvider", _providerUri)
.HonoursPactWith("TaxonomyGraphQLConsumer")
// .PactUri(@"..\..\..\..\..\pacts\taxonomygraphqlconsumer-taxonomygraphqlprovider.json")
.PactUri("
https://blnmanagermobilesvc.pact.dius.com.au/pacts/provider/TaxonomyGraphQLProvider/consumer/TaxonomyGraphQLConsumer/latest", new PactUriOptions("MyAPIKey"))
.Verify();
}
}
public virtual void Dispose()
{
}
}
}```
Please advise if you need further details to look at this. I am hoping this is a simple formatting issue that I missing given the fact that I've been staring at this for hours! Thank you much!!