【问题标题】:PACT Consumer Driven setUP test data in ProviderProvider 中的 PACT Consumer Driven setUP 测试数据
【发布时间】:2017-06-01 16:26:36
【问题描述】:

我正在执行一些测试,如果消费者设置了一些 ID 或提供者数据库中不存在的任何文本,那么我想在提供者测试中执行以下步骤

  • 接收带有信息的 PACT 文件,首先需要设置哪些内容
  • 然后我将拥有我的函数,它将开始将那些不可用的数据插入数据库中
  • 然后对 进行 API 调用,这将提供实际响应。

现在我想知道,Consumer 应该使用哪个字段让 Provider 知道,在实际 API 调用之前需要一些先决条件或预先设置。

我看到了示例,其中有一个 setUp : InsertIntoDatabase 但没有说明如何找到消费者提供的输入。

【问题讨论】:

  • 您使用什么语言?你在追随哪个例子?你能提供代码来帮助我们弄清楚你在做什么吗?
  • 我使用 .NET 作为语言并使用规范 v 1。并且我已经提交了示例代码。请让我知道这是否有助于理解我正在努力实现的目标

标签: pact


【解决方案1】:
[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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多