public async Task ReadSingleEntityReferenceLinkWorksAsExpected(ODataVersion version, string referenceLink) { // Arrange string payload = "{" + // -> ResourceStart "\"@odata.context\":\"http://localhost/$metadata#Customers/$entity\"," + "\"CustomerID\": 7," + referenceLink + "}"; IEdmEntitySet customers = Model.EntityContainer.FindEntitySet("Customers"); Assert.NotNull(customers); // Guard // Act Func <ODataMessageReader, Task <ODataReader> > func = mr => mr.CreateODataResourceReaderAsync(customers, customers.EntityType()); ODataItemWrapper item = await ReadPayloadAsync(payload, Model, func, version); // Assert Assert.NotNull(item); ODataResourceWrapper resource = Assert.IsType <ODataResourceWrapper>(item); ODataNestedResourceInfoWrapper nestedResourceInfo = Assert.Single(resource.NestedResourceInfos); Assert.Equal("Order", nestedResourceInfo.NestedResourceInfo.Name); if (version == ODataVersion.V401) { // --- Resource // |--- NestedResourceInfo (Order) // |--- Resource ODataResourceWrapper order = Assert.IsType <ODataResourceWrapper>(nestedResourceInfo.NestedResource); Assert.Equal("http://svc/Orders(8)", order.Resource.Id.OriginalString); Assert.Empty(order.Resource.Properties); } else { // --- Resource // |--- NestedResourceInfo (Order) // |--- EntityReferenceLink ODataEntityReferenceLinkWrapper orderLink = Assert.IsType <ODataEntityReferenceLinkWrapper>(Assert.Single(nestedResourceInfo.NestedLinks)); Assert.Equal("http://svc/Orders(7)", orderLink.EntityReferenceLink.Url.OriginalString); } }
/// <summary> /// Create <see cref="ODataResourceWrapper"/> from a <see cref="ODataEntityReferenceLinkWrapper"/> /// </summary> /// <param name="edmPropertyType">The Edm property type.</param> /// <param name="refLink">The reference link.</param> /// <param name="readContext">The reader context.</param> /// <returns>The created <see cref="ODataResourceSetWrapper"/>.</returns> private static ODataResourceWrapper CreateResourceWrapper(IEdmTypeReference edmPropertyType, ODataEntityReferenceLinkWrapper refLink, ODataDeserializerContext readContext) { Contract.Assert(edmPropertyType != null); Contract.Assert(refLink != null); Contract.Assert(readContext != null); ODataResource resource = new ODataResource { TypeName = edmPropertyType.FullName(), }; resource.Properties = CreateKeyProperties(refLink.EntityReferenceLink.Url, readContext) ?? Array.Empty <ODataProperty>(); ODataResourceWrapper resourceWrapper = new ODataResourceWrapper(resource); foreach (var instanceAnnotation in refLink.EntityReferenceLink.InstanceAnnotations) { resource.InstanceAnnotations.Add(instanceAnnotation); } return(resourceWrapper); }