public async Task BindModel_WithNestedCollectionContainingARecursiveRelation() { // Arrange Dictionary <string, string> bodyParameters = new Dictionary <string, string> { { "People[0].Name", "Person 0" }, { "People[0].Sibling.Name", "Person 0 Sibling" }, { "People[1].Sibling.Name", "Person 1 Sibling" }, { "People[2].Sibling", "Person 2 Sibling" }, { "People[1000].Name", "Person 1000 Sibling" }, }; HttpRequestMessage request = new HttpRequestMessage( HttpMethod.Post, "http://localhost/ModelBinding/NestedCollectionOfRecursiveTypes" ) { Content = new FormUrlEncodedContent(bodyParameters) }; // Act HttpResponseMessage response = await SubmitRequestAsync(request); // Assert PeopleModel result = await ReadAsJson <PeopleModel>(response); Assert.Equal(3, result.People.Count); Person person = result.People[0]; Assert.Equal("Person 0", person.Name); Assert.Equal("Person 0 Sibling", person.Sibling.Name); Assert.Null(person.Sibling.Sibling); person = result.People[1]; Assert.Equal("Person 1 Sibling", person.Sibling.Name); Assert.Null(person.Sibling.Sibling); person = result.People[2]; Assert.Null(person.Name); Assert.NotNull(person.Sibling); Assert.Null(person.Sibling.Name); }
public async Task BindModel_WithNestedCollectionContainingRecursiveRelation_WithMalformedValue() { // Arrange Dictionary <string, string> bodyParameters = new Dictionary <string, string> { { "People", "Person 0" }, }; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/ModelBinding/NestedCollectionOfRecursiveTypes") { Content = new FormUrlEncodedContent(bodyParameters) }; // Act HttpResponseMessage response = await SubmitRequestAsync(request); // Assert PeopleModel result = await ReadAsJson <PeopleModel>(response); Person person = Assert.Single(result.People); Assert.Null(person.Name); Assert.Null(person.Sibling); }
public PeopleModel NestedCollectionType([FromBody] PeopleModel model) { return(model); }