这是我的 Pact 类的样子,您可以看到 PactDir 已指定。当测试通过时,它只创建日志文件夹/文件,而不是契约合约。
PactBuilder = new PactBuilder(new PactConfig
{
SpecificationVersion = "2.0.0",
PactDir = @"C:\temp\pacts",
LogDir = @"c:\temp\logs"
});
这就是测试文件的样子。使用 nUnit 框架。
[Test]
public void Consumer_Test()
{
//ARRANGE
_mockProviderService
.Given("Testing service")
.UponReceiving("My API")
.With(new ProviderServiceRequest
{
Method = HttpVerb.Post,
Path = "/documents/",
Headers = new Dictionary<string, object>
{
{ "Accept", "application/json" }
}
})
.WillRespondWith(new ProviderServiceResponse
{
Status = 200,
Headers = new Dictionary<string, object>
{
{ "Content-Type", "application/json; charset=utf-8" }
},
Body = new
{
id = 1,
name = "joe"
}
});
//ACT
var consumer = new ApiClient(_mockProviderServiceBaseUri);
var result = consumer.GetStatusCode().GetAwaiter().GetResult();
//ASSERT
Assert.AreEqual(1, result.id);
Assert.AreEqual("joe", result.name);
_mockProviderService.VerifyInteractions();
}