I'm trying to creat a contract test in VSCode. I have this C# test class:
using xunit;
namespace PactTests.PactTests
{
public class ConsumerTest : IClassFixture<ConsumerPact>
{
private IMockProviderService _mockProviderService;
private string _mockProviderServiceBaseUri;
public ConsumerTest(ConsumerPact data)
{
_mockProviderService = data.MockProviderService;
_mockProviderService.ClearInteractions(); //NOTE: Clears any previously registered interactions before the test is run
_mockProviderServiceBaseUri = data.MockProviderServiceBaseUri;
}
[Fact]
public void OKResponse()
{
//Arrange
_mockProviderService
.Given("user token")
.UponReceiving("GET user token")
.With(new ProviderServiceRequest
{
Method = HttpVerb.Get,
Path = "/token/1234",
Headers = new Dictionary<string, object>
{
{ "application/json, text/plain, */*" }
}
})
.WillRespondWith(new ProviderServiceResponse
{
Status = 200,
Headers = new Dictionary<string, object>
{
{ "Content-Type", "application/json" }
},
Body = new //NOTE: Note the case sensitivity here, the body will be serialised as per the casing defined
{
token = "bearer"
}
}); //NOTE: WillRespondWith call must come last as it will register the interaction
var consumer = new SomethingApiClient(_mockProviderServiceBaseUri);
//Act
var result = consumer.GetSomething("tester");
//Assert
Assert.Equal("tester", result.id);
_mockProviderService.VerifyInteractions(); //NOTE: Verifies that interactions registered on the mock provider are called at least once
}
}
}
When I run the command dotnet test
I get these errors:
$ dotnet test ConsumerTest.cs(1,7): error CS0246: The type or namespace name 'xunit' could not be found (are you missing a using directive or an assembly reference?) [/Users/me/git/pact/consumer/PactTests.csproj] ConsumerTest.cs(5,31): error CS0246: The type or namespace name 'IClassFixture<>' could not be found (are you missing a using directive or an assembly reference?) [/Users/me/git/pact/consumer/PactTests.csproj] ConsumerTest.cs(7,13): error CS0246: The type or namespace name 'IMockProviderService' could not be found (are you missing a using directive or an assembly reference?) [/Users/me/git/pact/consumer/PactTests.csproj] ConsumerTest.cs(17,6): error CS0246: The type or namespace name 'FactAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/me/git/pact/consumer/PactTests.csproj] ConsumerTest.cs(17,6): error CS0246: The type or namespace name 'Fact' could not be found (are you missing a using directive or an assembly reference?) [/Users/me/git/pact/consumer/PactTests.csproj]
This was my .csproj
file:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.VisualStudio.TestPlatform" Version="14.0.0.1" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="PactNet" Version="2.0.17" />
<PackageReference Include="PactNet.OSX" Version="2.0.17" />
</ItemGroup>
</Project>
I added <PackageReference Include="xunit" Version="2.4.1" />
but it made no difference. How do I resolve this?