我在 dotnet 下进行消费者合约测试时出现“互操作异常”

问题描述 投票:0回答:1

我有使用 pact v3 的代码。我已升级到 pact v4,并按照升级指南中的说明进行操作。

当我运行契约消费者测试时,出现以下错误:

 Message:  PactNet.Exceptions.PactFailureException : Unable to perform
 the given action. The interop call indicated failure
 
   Stack Trace:  InteropActionExtensions.CheckInteropSuccess(Boolean
 success) HttpInteractionDriver.WithRequest(String method, String path)
 RequestBuilder.WithRequest(String method, String path)
 RequestBuilder.WithRequest(HttpMethod method, String path)
 IRequestBuilderV2.WithRequest(HttpMethod method, String path)
 CasClientPact.EnsureCasClientHandlesAddItemEndpointWhenAlreadyIn() line 63

版本

  • 操作系统:Windows 11
  • 点网:net6.0
  • PactNet:4.5.0
  • N单位:3.13.3
  • NUnit3TestAdapter:4.5.0
  • Microsoft.NET.Test.Sdk:17.7.2

演示项目

示例代码:

using NUnit.Framework;
using PactNet.Infrastructure.Outputters;
using PactNet;
      public CasClientPact()
      {
          var config = new PactConfig
          {
              PactDir = @"..\..\..\..\artifacts\pacts"
          };
          IPactV2 pact = Pact.V2("CasClient", "Cas", config);
          this.pact = pact.WithHttpInteractions(9222);
      }
    
       [Test]
       async public Task EnsureCasClientHandlesAddItemEndpointWhenAlreadyIn()
       {
           pact
          .UponReceiving("A request to add item that is already stored")
          .WithRequest(HttpMethod.Post, "/cas/someNs")
          .WithBody("alreadyin", "application/octet-stream")
          .WillRespond()
          .WithStatus(200)
          .WithBody("/cas/someNs/content/-AFBB8Hv7uIEEmV1Srn0Y-OkfnMplM-FX8TEh4-SucM", "text/plain; charset=utf-8");
    
           await pact.VerifyAsync(async ctx =>
           {
               byte[] bytes = Encoding.ASCII.GetBytes("alreadyin");
               var result = await Client.AddItemAsync("someNs", bytes, "application/octet-stream");
               Assert.AreEqual("/cas/someNs/content/-AFBB8Hv7uIEEmV1Srn0Y-OkfnMplM-FX8TEh4-SucM", result);
           });
       }
.net pact
1个回答
-1
投票

当 .Given 调用中包含土耳其语字符(具体为 ş 或 ı)时,我收到此错误。您的代码没有 .Given 调用,这可能是原因吗?

© www.soinside.com 2019 - 2024. All rights reserved.