契约网如何动态提供响应主体?

时间:2018-12-06 12:45:11

标签: pact-net

我在点网核心中使用pact-dotnet核心nuget编写合同测试。

在消费者测试中,如何动态指定body参数,我的意思是我想从文件中读取预期的响应并将其注入。 例如

      **var expectedResponse = FileReader.GetJsonObject("GetCustomerResponse.json", 
            _environment);**

        // Arrange
        _mockProviderService.Given("There is data")
            .UponReceiving("A valid GET request for get customer1")
            .With(new ProviderServiceRequest
            {
                Method = HttpVerb.Get,
                Path = "/customers/1234"
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status = 200,
                Headers = new Dictionary<string, object>
                {
                    { "Content-Type", "application/json; charset=utf-8" }
                },
                Body = **expectedResponse** 
            });

谢谢!

0 个答案:

没有答案