0

我正在尝试在 VSCode 中创建合同测试。我有这个 C# 测试类:

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
    }
  }
}

当我运行命令时,dotnet test我收到以下错误:

$ dotnet test ConsumerTest.cs(1,7): error CS0246: The type or namespace name 'xunit' could not be found(你是否缺少 using 指令或程序集引用?) [/Users/me/git/pact/ consumer/PactTests.csproj] ConsumerTest.cs(5,31):错误 CS0246:找不到类型或命名空间名称“IClassFixture<>”(您是否缺少 using 指令或程序集引用?) [/Users/me /git/pact/consumer/PactTests.csproj] ConsumerTest.cs(7,13):错误 CS0246:找不到类型或命名空间名称“IMockProviderService”(您是否缺少 using 指令或程序集引用?) [/ Users/me/git/pact/consumer/PactTests.csproj] ConsumerTest.cs(17,6):错误 CS0246:类型或命名空间名称“FactAttribute”找不到(您是否缺少 using 指令或程序集引用?) [/Users/me/git/pact/consumer/PactTests.csproj] ConsumerTest.cs(17,6): error CS0246: The type or namespace name找不到“事实”(您是否缺少 using 指令或程序集引用?) [/Users/me/git/pact/consumer/PactTests.csproj]

这是我的.csproj文件:

<?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>

我添加了<PackageReference Include="xunit" Version="2.4.1" />,但没有任何区别。我该如何解决这个问题?

4

0 回答 0