首页 > 解决方案 > 验证提供商端时无法从 dotnet 核心中的 Pact Brocker 获取 PACT

问题描述

我已经在 C# dotnet core 的消费者端实现了 PACT,并且能够使用以下代码将 *.json pact 文件发布到 PactBrocker。

var pactPublisher = new PactPublisher("http://domain.pact.dius.com.au", new PactUriOptions("***", "***"));

pactPublisher.PublishToBroker($"..\pacts\userservice.api-event.api.json",
                        "1.0.2");

在提供者方面(再次在 C# dotnet core 中),当我尝试使用单元测试用例(参见下面的代码)验证相同的已发布 Pact 时:

[Fact]
public void EnsureEventApiHonoursPactWithConsumer()
{        
    //Arrange
    // createing the "config" object

    //Act / Assert
    IPactVerifier pactVerifier = new PactVerifier(config);

          pactVerifier
            .ProviderState($"{_providerUri}/provider-states")
            .ServiceProvider("Event.API", _providerUri)
            .HonoursPactWith("UserService.API")
       .PactUri("http://domain.pact.dius.com.au/pacts/provider/Event.API/consumer/UserService.API/version/1.0.2", new PactUriOptions("***", "***")).Verify();
}

运行该单元测试时出现以下错误。

PactNet.PactFailureException :协议验证失败。有关详细信息,请参阅输出。如果输出为空,请为您的测试框架提供自定义 config.Outputters (IOutput),因为我们无法写入控制台。在 C:\projects\pact-net\PactNet\Core\PactCoreHost.cs:line 139 中的 PactNet.Core.PactCoreHost`1.Start()

在 C:\POC\pact2\Event.Api\Event.Test\EventAPITests.cs:line 55 中的 Event.Test.EventApiTests.EnsureEventApiHonoursPactWithConsumer()

从http://domain.pact.dius.com.au/pacts/provider/Event.API/consumer/UserService.API/version/1.0.2读取文件时出错

由于目标机器主动拒绝,无法建立连接。- 连接(2)“domain.pact.dius.com.au”端口 80 C:/POC/pact2/Event.Api/Event.Test/bin/Debug/netcoreapp2.0/pact-win32/lib/ruby/ lib/ruby/2.2.0/net/http.rb:879:in `initialize'

C:/POC/pact2/Event.Api/Event.Test/bin/Debug/netcoreapp2.0/pact-win32/lib/ruby/lib/ruby/2.2.0/net/http.rb:879:in `open '

C:/POC/pact2/Event.Api/Event.Test/bin/Debug/netcoreapp2.0/pact-win32/lib/ruby/lib/ruby/2.2.0/net/http.rb:879:in `block在连接'

C:/POC/pact2/Event.Api/Event.Test/bin/Debug/netcoreapp2.0/pact-win32/lib/ruby/lib/ruby/2.2.0/timeout.rb:74:in `timeout'

C:/POC/pact2/Event.Api/Event.Test/bin/Debug/netcoreapp2.0/pact-win32/lib/ruby/lib/ruby/2.2.0/net/http.rb:878:in `connect '

C:/POC/pact2/Event.Api/Event.Test/bin/Debug/netcoreapp2.0/pact-win32/lib/ruby/lib/ruby/2.2.0/net/http.rb:863:in`do_start '

C:/POC/pact2/Event.Api/Event.Test/bin/Debug/netcoreapp2.0/pact-win32/lib/ruby/lib/ruby/2.2.0/net/http.rb:852:in`start '

有人可以帮忙解决这个错误吗?PACT 代理服务器不在我的控制范围内。我是从http://pact.dius.com.au/网站获得的。

标签: .netpact-broker

解决方案


得到了答案。我在我办公室的代理环境中。它在我家很好用。我还需要点击 https(端口 443)而不是 http(端口 80)。


推荐阅读