C#-PACT .NET使用者测试:灵活的长度数组

我正在使用pactNet来测试API,该API应该返回灵活长度的数组.

如果我叫“ myApi / items /”,它应该返回消费者不知道确切尺寸的物品清单.
因此答案应如下所示:

    [
        {
            "id": "1",
            "description": "foo"
        },
        {
            "id": "2",
            "description": "foo2"
        },
        {
            "id": "3",
            "description": "foo3"
        }
    ]

或这个:

    [
        {
            "id": "4",
            "description": "foo4"
        },
        {
            "id": "2",
            "description": "foo2"
        }
    ]

如何为此互动创建合同?

documentation中,是Ruby中的一个示例,但是我在C#中找不到等效的示例.

我正在使用pactNet 2.1.1版.

编辑:这是一个示例,它应该是什么样子.我想知道的是如何声明主体应包含长度灵活的项目数组.

[Test]
    public void GetAllItems()
    {
        //Arrange
        _mockProviderService
            .Given("There are items")
            .UponReceiving("A GET request to retrieve the items")
            .With(new ProviderServiceRequest
            {
                Method = HttpVerb.Get,
                Path = "/items/",
                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 = // array of items with some attributes
                       // (somthing like: {"id": "2", "description": "foo"}) 
                       // with flexible length
            });

        var consumer = new ItemApiClient(_mockProviderServiceBaseUri);

        //Act
        var result = consumer.GetItems();

        //Assert
        Assert.AreEqual(true, result.Count > 0);

        _mockProviderService.VerifyInteractions();

        data.Dispose();
    }

解决方法:

听起来您正在寻找MinTypeMatcher.

主体部分如下所示:

Body = Match.MinType(new { id: "1", description: "foo" }, 1)
上一篇:javascript-如何在协定中使用协定


下一篇:php_rce