2017-11-17 30 views
2

가변 길이의 배열을 반환해야하는 API를 테스트하기 위해 pactNet을 사용하고 있습니다.PACT .NET 소비자 테스트 : 가변 길이 배열

"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(); 
    } 

답변

3

여러분이 MinTypeMatcher를 찾고있는 것처럼 들립니다.

몸 부분은 다음과 같을 것이다 :

Body = Match.MinType(new { id: "1", description: "foo" }, 1) 
+0

감사합니다! 그게 내가 찾고 있던 것 같아. –