我正在执行一些测试,如果Consumer设置了一些ID或者在Provider Database中不存在的任何Text,那么我想在Provider Tests中执行以下步骤
现在我想知道,消费者应该使用哪个字段让提供商知道,在实际API调用之前需要一些先决条件或预先设置。
我看到了样本,其中有一个setUp:InsertIntoDatabase,但没有说明如何找到消费者提供的输入。
答案 0 :(得分:0)
[TestMethod]
public void Ensure_OfferApi_HonoursPact_WithDeal_ForSendingLatestSoftOffer()
{
//Arrange
var outputter = new CustomOutputter();
var config = new PactVerifierConfig();
config.ReportOutputters.Add(outputter);
IPactVerifier pactVerifier = new PactVerifier(() => { InsertEventIntoDatabase(); }, () => { }, config);
pactVerifier
.ProviderState(
"Given the Offer Exist in Offer System I WANT TO See Latest SoftOffer",
setUp: InsertEventsIntoDatabase); // in case you want to insert something
//Act / Assert
using (var client = new HttpClient { BaseAddress = new Uri("http://localhost:9999") })
{
pactVerifier
.ServiceProvider("Offer API", client)
.HonoursPactWith("Consumer")
.PactUri(@"C:\TOSS\TestSample\log\deal-offer.json")
.Verify();
}
// Verify that verifaction log is also sent to additional reporters defined in the config
Assert.IsNotNull(outputter.Output);
}
Lets say the setup function is InsertEventsIntoDatabase and I want to add events what ever consumer is providing via PACT file. so that I dont need to update this code when ever Consumer changes the input.