/// <inheritdoc /> public override async Task <object> ReadAsync(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) { if (messageReader == null) { throw Error.ArgumentNull(nameof(messageReader)); } if (readContext == null) { throw Error.ArgumentNull(nameof(readContext)); } IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); // TODO: is it ok to read the top level collection of entity? if (!(edmType.IsCollection() && edmType.AsCollection().ElementType().IsStructured())) { throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, EdmTypeKind.Complex + " or " + EdmTypeKind.Entity); } ODataReader resourceSetReader = await messageReader.CreateODataResourceSetReaderAsync().ConfigureAwait(false); object resourceSet = await resourceSetReader.ReadResourceOrResourceSetAsync().ConfigureAwait(false); return(ReadInline(resourceSet, edmType, readContext)); }
public async Task ReadResourceSetInResponseMessageAsync() { var payload = @" HTTP/1.1 200 OK Content-Type: application/json OData-Version: 4.0 {""@odata.context"":""http://tempuri.org/$metadata#Customers"",""@odata.count"":1,""value"":[{""Id"":1,""Name"":""Customer 1""}]}"; await SetupRawInputContextAndRunTestAsync( payload, async (rawInputContext) => { var asynchronousReader = await rawInputContext.CreateAsynchronousReaderAsync(); var responseMessage = await asynchronousReader.CreateResponseMessageAsync(); Assert.Equal(200, responseMessage.StatusCode); Assert.Contains(new KeyValuePair <string, string>("Content-Type", "application/json"), responseMessage.Headers); Assert.Contains(new KeyValuePair <string, string>("OData-Version", "4.0"), responseMessage.Headers); using (var messageReader = new ODataMessageReader(responseMessage, new ODataMessageReaderSettings(), this.model)) { var jsonLightReader = await messageReader.CreateODataResourceSetReaderAsync(this.customerEntitySet, this.customerEntityType); await DoReadAsync( jsonLightReader as ODataJsonLightReader, verifyResourceSetAction: (resourceSet) => { Assert.NotNull(resourceSet); Assert.Equal(1, resourceSet.Count); }, verifyResourceAction: (resource) => { Assert.NotNull(resource); Assert.Equal("NS.Customer", resource.TypeName); var properties = resource.Properties.ToArray(); Assert.Equal(2, properties.Length); Assert.Equal("Id", properties[0].Name); Assert.Equal(1, properties[0].Value); Assert.Equal("Name", properties[1].Name); Assert.Equal("Customer 1", properties[1].Value); }); } }); }