public void ApplyDerivedComplexForBaseComplexTypeProperty() { TestMaterializerContext context = new TestMaterializerContext(); context.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { if (name == "DerivedComplexType") { var edmType = context.Model.GetOrCreateEdmType(typeof(DerivedComplexType)); return(new ClientTypeAnnotation(edmType, typeof(DerivedComplexType), "DerivedComplexType", context.Model)); } else { var edmType = context.Model.GetOrCreateEdmType(typeof(ComplexTypeWithChildComplexType)); return(new ClientTypeAnnotation(edmType, typeof(ComplexTypeWithChildComplexType), "ComplexTypeWithChildComplexType", context.Model)); } }; ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = new DerivedComplexType { DerivedProp = 1 }; var innerResource = new ODataResource() { TypeName = "DerivedComplexType", Properties = new ODataProperty[] { new ODataProperty { Name = "DerivedProp", Value = 2 } } }; this.ApplyInnerProperty(innerResource, complexInstance, context); Assert.Equal(2, (complexInstance.InnerComplexProperty as DerivedComplexType).DerivedProp); }
internal ODataEntriesEntityMaterializer CreateODataEntriesEntityMaterializer( List <ODataResource> resources, Type resourceType, TestMaterializerContext materializerContext = null) { var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); var resourceSet = new ODataResourceSet(); MaterializerFeed.CreateFeed(resourceSet, resources); resources.ForEach(r => { if (r == null) { MaterializerEntry.CreateEmpty(); } else { MaterializerEntry.CreateEntry(r, ODataFormat.Json, true, clientEdmModel); } }); materializerContext = materializerContext ?? new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context); QueryComponents components = new QueryComponents(new Uri("http://foo.com/Service"), new Version(4, 0), resourceType, null, new Dictionary <Expression, Expression>()); return(new ODataEntriesEntityMaterializer(resources, materializerContext, adapter, components, resourceType, null, ODataFormat.Json)); }
public void MaterializeDerivedComplexForBaseComplexTypeProperty() { TestMaterializerContext context = new TestMaterializerContext(); //In a true client, a TypeResolver will be used to resolve derived property type. context.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { var edmType = context.Model.GetOrCreateEdmType(typeof(DerivedComplexType)); return(new ClientTypeAnnotation(edmType, typeof(DerivedComplexType), "DerivedComplexType", context.Model)); }; var derivedResource = new ODataResource() { TypeName = "DerivedComplexType", Properties = new ODataProperty[] { new ODataProperty { Name = "DerivedProp", Value = 1 } } }; var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var materializerEntry = MaterializerEntry.CreateEntry(derivedResource, ODataFormat.Json, true, clientEdmModel); this.CreateEntryMaterializationPolicy(context).Materialize(materializerEntry, typeof(ChildComplexType), false); var derived = materializerEntry.ResolvedObject as DerivedComplexType; Assert.NotNull(derived); Assert.Equal(1, derived.DerivedProp); }
internal ComplexValueMaterializationPolicy CreatePrimitiveValueMaterializationPolicy() { TestMaterializerContext context = new TestMaterializerContext() { Context = new DSClient.DataServiceContext() }; return(CreatePrimitiveValueMaterializationPolicy(context)); }
public void DataServicCollectionOfTAsCollectionTypeShouldFailForPrimitiveOrComplexCollections() { var testContext = new TestMaterializerContext(); var edmType = testContext.Model.GetOrCreateEdmType(typeof(MyInfo)); var clientTypeAnnotation = new ClientTypeAnnotation(edmType, typeof(MyInfo), "MyInfo", testContext.Model); Action test = () => this.CreateCollectionValueMaterializationPolicy(testContext).CreateCollectionInstance((IEdmCollectionTypeReference)clientTypeAnnotation.EdmTypeReference, clientTypeAnnotation.ElementType); test.ShouldThrow <InvalidOperationException>().WithMessage(DSClient.Strings.AtomMaterializer_DataServiceCollectionNotSupportedForNonEntities); }
public void NonMissingMethodExceptionOnCreateInstanceShouldNotBeCaught() { var testContext = new TestMaterializerContext(); var edmType = testContext.Model.GetOrCreateEdmType(typeof(ListWithNoEmptyConstructors)); var clientTypeAnnotation = new ClientTypeAnnotation(edmType, typeof(ErrorThrowingList), "Points", testContext.Model); Action test = () => this.CreateCollectionValueMaterializationPolicy(testContext).CreateCollectionInstance((IEdmCollectionTypeReference)clientTypeAnnotation.EdmTypeReference, clientTypeAnnotation.ElementType); test.ShouldThrow <TargetInvocationException>().WithInnerException <ApplicationException>().WithInnerMessage("foo"); }
public void NullValueShouldBeAppliedToSubComplexValueProperty() { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = new ChildComplexType(); this.ApplyInnerProperty(null, complexInstance); Assert.Null(complexInstance.InnerComplexProperty); }
public void CreateCollectionInstanceShouldFailOnTypeWithNoParametersLessConstructors() { var testContext = new TestMaterializerContext(); var edmType = testContext.Model.GetOrCreateEdmType(typeof(ListWithNoEmptyConstructors)); var clientTypeAnnotation = new ClientTypeAnnotation(edmType, typeof(ListWithNoEmptyConstructors), "Points", testContext.Model); Action test = () => this.CreateCollectionValueMaterializationPolicy(testContext).CreateCollectionInstance((IEdmCollectionTypeReference)clientTypeAnnotation.EdmTypeReference, clientTypeAnnotation.ElementType); test.ShouldThrow <InvalidOperationException>().WithMessage(DSClient.Strings.AtomMaterializer_MaterializationTypeError(clientTypeAnnotation.ElementType.FullName)); }
public void ApplyStringValueForCollectionPropertyShouldError() { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); ODataProperty property = new ODataProperty() { Name = "Strings", Value = "foo" }; Action test = () => this.CreateEntryMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance); test.ShouldThrow <InvalidOperationException>().WithMessage(DSClient.Strings.Deserialize_MixedTextWithComment); }
public void ApplyODataComplexValueForCollectionPropertyShouldError() { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataComplexValue() }; Action test = () => this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance); test.ShouldThrow <InvalidOperationException>().WithMessage(DSClient.Strings.AtomMaterializer_InvalidCollectionItem(property.Name)); }
public void ApplyODataCollectionValueToNonNullExistingCollectionProperty() { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); complexInstance.Strings.Add("ShouldBeCleared"); ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataCollectionValue() }; this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance); complexInstance.Strings.Should().HaveCount(0); }
public void NullValueShouldBeAppliedToSubComplexValueProperty() { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = new ChildComplexType(); ODataProperty property = new ODataProperty() { Name = "InnerComplexProperty", Value = null }; this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithChildComplexType), null), property, complexInstance); Assert.IsNull(complexInstance.InnerComplexProperty); }
public void ApplyNonExistantPropertyWithIgnoreMissingPropertiesShouldNotError() { TestMaterializerContext context = new TestMaterializerContext() { IgnoreMissingProperties = true }; CollectionValueMaterializationPolicyTests.Point point = new CollectionValueMaterializationPolicyTests.Point(); ODataProperty property = new ODataProperty() { Name = "Z", Value = 10 }; this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(CollectionValueMaterializationPolicyTests.Point), null), property, point); }
public void ApplyNonExistantPropertyWithIgnoreMissingPropertiesShouldNotError() { TestMaterializerContext context = new TestMaterializerContext() { UndeclaredPropertyBehavior = DSClient.UndeclaredPropertyBehavior.Support }; CollectionValueMaterializationPolicyTests.Point point = new CollectionValueMaterializationPolicyTests.Point(); ODataProperty property = new ODataProperty() { Name = "Z", Value = 10 }; this.CreateEntryMaterializationPolicy(context) .ApplyDataValue(context.ResolveTypeForMaterialization(typeof(CollectionValueMaterializationPolicyTests.Point), null), property, point); }
public void ShouldMaterializeConcreteComplexCollectionDeclaredAsAbstract() { var pointResources = new List <ODataResource>(new[] { new ODataResource() { Properties = new ODataProperty[] { new ODataProperty() { Name = "Points", Value = 0 }, new ODataProperty() { Name = "Diameter", Value = 15 } } }, new ODataResource() { Properties = new ODataProperty[] { new ODataProperty() { Name = "Points", Value = 0 }, new ODataProperty() { Name = "Diameter", Value = 18 } } }, }); var testContext = new TestMaterializerContext(); testContext.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { var edmType = testContext.Model.GetOrCreateEdmType(typeof(CollectionValueMaterializationPolicyTests.Circle)); return(new ClientTypeAnnotation(edmType, typeof(CollectionValueMaterializationPolicyTests.Circle), "Circle", testContext.Model)); }; var outputCollection = new List <CollectionValueMaterializationPolicyTests.Shape>(); var entriesMaterializer = CreateODataEntriesEntityMaterializer(pointResources, typeof(CollectionValueMaterializationPolicyTests.Shape), testContext); while (entriesMaterializer.Read()) { outputCollection.Add(entriesMaterializer.CurrentValue as CollectionValueMaterializationPolicyTests.Shape); } outputCollection.Should().HaveCount(2); outputCollection[0].Points.Should().Be(0); ((CollectionValueMaterializationPolicyTests.Circle)outputCollection[0]).Diameter.Should().Be(15); outputCollection[1].Points.Should().Be(0); ((CollectionValueMaterializationPolicyTests.Circle)outputCollection[1]).Diameter.Should().Be(18); }
public void ShouldMaterializeConcreteComplexCollectionDeclaredAsAbstract() { var complexValues = new List <ODataComplexValue>(new[] { new ODataComplexValue() { Properties = new ODataProperty[] { new ODataProperty() { Name = "Points", Value = 0 }, new ODataProperty() { Name = "Diameter", Value = 15 } } }, new ODataComplexValue() { Properties = new ODataProperty[] { new ODataProperty() { Name = "Points", Value = 0 }, new ODataProperty() { Name = "Diameter", Value = 18 } } }, }); var testContext = new TestMaterializerContext(); testContext.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { var edmType = testContext.Model.GetOrCreateEdmType(typeof(Circle)); return(new ClientTypeAnnotation(edmType, typeof(Circle), "Circle", testContext.Model)); }; var outputCollection = new List <Shape>(); var addToDelegate = ClientTypeUtil.GetAddToCollectionDelegate(outputCollection.GetType()); this.CreateCollectionValueMaterializationPolicy(testContext).ApplyCollectionDataValues( complexValues, "Shape", outputCollection, typeof(Shape), addToDelegate, true); outputCollection.Should().HaveCount(2); outputCollection[0].Points.Should().Be(0); ((Circle)outputCollection[0]).Diameter.Should().Be(15); outputCollection[1].Points.Should().Be(0); ((Circle)outputCollection[1]).Diameter.Should().Be(18); }
public void ApplyODataCollectionValueToNullCollectionProperty() { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); complexInstance.Strings = null; ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataCollectionValue() { Items = new string[] { "foo" }, TypeName = typeof(ComplexTypeWithPrimitiveCollection).FullName } }; this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance); complexInstance.Strings.Should().HaveCount(1); complexInstance.Strings[0].Should().Be("foo"); }
public void ValueShouldBeAppliedRegardlessIfPropertyStartsNullOrNot() { foreach (var startingPropertyState in new ChildComplexType[] { null, new ChildComplexType() }) { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = startingPropertyState; var innerEntry = new ODataResource() { Properties = new ODataProperty[] { new ODataProperty() { Name = "Prop", Value = 1 } } }; this.ApplyInnerProperty(innerEntry, complexInstance); complexInstance.InnerComplexProperty.Prop.Should().Be(1); } }
internal EntryValueMaterializationPolicy CreateEntryMaterializationPolicy(TestMaterializerContext materializerContext = null) { var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); materializerContext = materializerContext ?? new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context); var lazyPrimitivePropertyConverter = new Microsoft.OData.Client.SimpleLazy <PrimitivePropertyConverter>(() => new PrimitivePropertyConverter()); var primitiveValueMaterializerPolicy = new PrimitiveValueMaterializationPolicy(materializerContext, lazyPrimitivePropertyConverter); var entryPolicy = new EntryValueMaterializationPolicy(materializerContext, adapter, lazyPrimitivePropertyConverter, null); var collectionPolicy = new CollectionValueMaterializationPolicy(materializerContext, primitiveValueMaterializerPolicy); var intanceAnnotationPolicy = new InstanceAnnotationMaterializationPolicy(materializerContext); entryPolicy.CollectionValueMaterializationPolicy = collectionPolicy; entryPolicy.InstanceAnnotationMaterializationPolicy = intanceAnnotationPolicy; return(entryPolicy); }
public void CreateCollectionPropertyInstanceShouldFailOnTypeWithNoParametersLessConstructors() { var odataProperty = new ODataProperty() { Name = "foo", Value = new ODataCollectionValue() { TypeName = "Points" } }; var testContext = new TestMaterializerContext(); testContext.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { var edmType = testContext.Model.GetOrCreateEdmType(typeof(ListWithNoEmptyConstructors)); return(new ClientTypeAnnotation(edmType, typeof(ListWithNoEmptyConstructors), "ListWithNoEmptyConstructors", testContext.Model)); }; Action test = () => this.CreateCollectionValueMaterializationPolicy(testContext).CreateCollectionPropertyInstance(odataProperty, typeof(ListWithNoEmptyConstructors)); test.ShouldThrow <InvalidOperationException>().WithMessage(DSClient.Strings.AtomMaterializer_NoParameterlessCtorForCollectionProperty("foo", typeof(ListWithNoEmptyConstructors).Name)); }
public void ShortIntegrationTestToValidateEntryShouldBeRead() { var odataEntry = new ODataResource() { Id = new Uri("http://services.odata.org/OData/OData.svc/Customers(0)") }; odataEntry.Properties = new ODataProperty[] { new ODataProperty() { Name = "ID", Value = 0 }, new ODataProperty() { Name = "Description", Value = "Simple Stuff" } }; var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); MaterializerEntry.CreateEntry(odataEntry, ODataFormat.Json, true, clientEdmModel); var materializerContext = new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context); QueryComponents components = new QueryComponents(new Uri("http://foo.com/Service"), new Version(4, 0), typeof(Customer), null, new Dictionary <Expression, Expression>()); var entriesMaterializer = new ODataEntriesEntityMaterializer(new ODataResource[] { odataEntry }, materializerContext, adapter, components, typeof(Customer), null, ODataFormat.Json); var customersRead = new List <Customer>(); // This line will call ODataEntityMaterializer.ReadImplementation() which will reconstruct the entity, and will get non-public setter called. while (entriesMaterializer.Read()) { customersRead.Add(entriesMaterializer.CurrentValue as Customer); } customersRead.Should().HaveCount(1); customersRead[0].ID.Should().Be(0); customersRead[0].Description.Should().Be("Simple Stuff"); }
public void ValueShouldBeAppliedRegardlessIfPropertyStartsNullOrNot() { foreach (var startingPropertyState in new ChildComplexType[] { null, new ChildComplexType() }) { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = startingPropertyState; ODataProperty property = new ODataProperty() { Name = "InnerComplexProperty", Value = new ODataComplexValue() { Properties = new ODataProperty[] { new ODataProperty() { Name = "Prop", Value = 1 } } } }; this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithChildComplexType), null), property, complexInstance); complexInstance.InnerComplexProperty.Prop.Should().Be(1); } }
public void ApplyODataDerivedComplexValueForBaseComplexTypeProperty() { TestMaterializerContext context = new TestMaterializerContext(); ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = new DerivedComplexType { DerivedProp = 1 }; //In a true client, a TypeResolver will be used to resolve derived property type. context.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { if (name == "DerivedComplexType") { var edmType = context.Model.GetOrCreateEdmType(typeof(DerivedComplexType)); return(new ClientTypeAnnotation(edmType, typeof(DerivedComplexType), "DerivedComplexType", context.Model)); } else { var edmType = context.Model.GetOrCreateEdmType(typeof(ComplexTypeWithChildComplexType)); return(new ClientTypeAnnotation(edmType, typeof(ComplexTypeWithChildComplexType), "ComplexTypeWithChildComplexType", context.Model)); } }; IEdmType t = context.Model.GetOrCreateEdmType(typeof(DerivedComplexType)); ODataProperty property = new ODataProperty() { Name = "InnerComplexProperty", Value = new ODataComplexValue { TypeName = "DerivedComplexType", Properties = new ODataProperty[] { new ODataProperty { Name = "DerivedProp", Value = 1 } } } }; Action test = () => this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithChildComplexType), null), property, complexInstance); test.ShouldNotThrow(); }
internal ComplexValueMaterializationPolicy CreatePrimitiveValueMaterializationPolicy(TestMaterializerContext context) { var lazyPrimitivePropertyConverter = new DSClient.SimpleLazy <PrimitivePropertyConverter>(() => new PrimitivePropertyConverter(ODataFormat.Json)); var primitiveValueMaterializerPolicy = new PrimitiveValueMaterializationPolicy(context, lazyPrimitivePropertyConverter); var complexPolicy = new ComplexValueMaterializationPolicy(context, lazyPrimitivePropertyConverter); var collectionPolicy = new CollectionValueMaterializationPolicy(context, primitiveValueMaterializerPolicy); var intanceAnnotationPolicy = new InstanceAnnotationMaterializationPolicy(context); collectionPolicy.ComplexValueMaterializationPolicy = complexPolicy; complexPolicy.CollectionValueMaterializationPolicy = collectionPolicy; complexPolicy.InstanceAnnotationMaterializationPolicy = intanceAnnotationPolicy; return(complexPolicy); }
private void ApplyInnerProperty(ODataResource innerResource, ComplexTypeWithChildComplexType parentInstance, TestMaterializerContext context = null) { context = context ?? new TestMaterializerContext(); var resource = new ODataResource() { TypeName = "ComplexTypeWithChildComplexType", Properties = new ODataProperty[0] }; var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var materializerEntry = MaterializerEntry.CreateEntry(resource, ODataFormat.Json, false, clientEdmModel); materializerEntry.ResolvedObject = parentInstance; ODataNestedResourceInfo innerComplexP = new ODataNestedResourceInfo() { Name = "InnerComplexProperty", IsCollection = false }; MaterializerEntry innerMaterializerEntry; if (innerResource != null) { innerMaterializerEntry = MaterializerEntry.CreateEntry(innerResource, ODataFormat.Json, true, clientEdmModel); } else { innerMaterializerEntry = MaterializerEntry.CreateEmpty(); } MaterializerNavigationLink.CreateLink(innerComplexP, innerMaterializerEntry); materializerEntry.AddNestedResourceInfo(innerComplexP); var policy = this.CreateEntryMaterializationPolicy(context); policy.EntityTrackingAdapter.TargetInstance = parentInstance; policy.Materialize(materializerEntry, typeof(ComplexTypeWithChildComplexType), true); }
public void MaterializeEntityShouldWork() { var odataEntry = new OData.ODataResource() { Id = new Uri("http://www.odata.org/service.svc/entitySet(1)") }; odataEntry.Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "keyProp", Value = 1 }, new OData.ODataProperty { Name = "colorProp", Value = new OData.ODataEnumValue("blue") }, new OData.ODataProperty { Name = "primitiveCollection", Value = new OData.ODataCollectionValue { TypeName = "Edm.Int32", Items = new List <object> { 1, 2, 3 } } }, new OData.ODataProperty { Name = "enumCollection", Value = new OData.ODataCollectionValue { TypeName = "color", Items = new List <OData.ODataEnumValue> { new OData.ODataEnumValue("white"), new OData.ODataEnumValue("blue") } } } }; var complexP = new OData.ODataNestedResourceInfo() { Name = "complexProp", IsCollection = false }; var complexResource = new OData.ODataResource { Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "age", Value = 11 }, new OData.ODataProperty { Name = "name", Value = "June" } } }; var complexColP = new OData.ODataNestedResourceInfo { Name = "complexCollection", IsCollection = true }; var complexColResourceSet = new OData.ODataResourceSet(); var items = new List <OData.ODataResource> { new OData.ODataResource { Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "name", Value = "Aug" }, new OData.ODataProperty { Name = "age", Value = 8 }, new OData.ODataProperty { Name = "color", Value = new OData.ODataEnumValue("white") } } }, new OData.ODataResource { Properties = new OData.ODataProperty[] { new OData.ODataProperty { Name = "name", Value = "Sep" }, new OData.ODataProperty { Name = "age", Value = 9 }, new OData.ODataProperty { Name = "color", Value = new OData.ODataEnumValue("blue") } } } }; var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); var materializerEntry = MaterializerEntry.CreateEntry(odataEntry, OData.ODataFormat.Json, true, clientEdmModel); MaterializerNavigationLink.CreateLink(complexP, MaterializerEntry.CreateEntry(complexResource, OData.ODataFormat.Json, true, clientEdmModel)); MaterializerFeed.CreateFeed(complexColResourceSet, items); MaterializerNavigationLink.CreateLink(complexColP, complexColResourceSet); var materializerContext = new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context); QueryComponents components = new QueryComponents(new Uri("http://foo.com/Service"), new Version(4, 0), typeof(EntityType), null, new Dictionary <Expression, Expression>()); var entriesMaterializer = new ODataEntriesEntityMaterializer(new OData.ODataResource[] { odataEntry }, materializerContext, adapter, components, typeof(EntityType), null, OData.ODataFormat.Json); var customersRead = new List <EntityType>(); while (entriesMaterializer.Read()) { customersRead.Add(entriesMaterializer.CurrentValue as EntityType); } customersRead.Should().HaveCount(1); customersRead[0].KeyProp.Should().Be(1); customersRead[0].ComplexProp.Should().Equals(new ComplexType { Age = 11, Name = "June" }); customersRead[0].ColorProp.Should().Equals(Color.Blue); customersRead[0].PrimitiveCollection.Should().Equals(new List <int> { 1, 2, 3 }); ComplexType complex1 = new ComplexType { Name = "Aug", Age = 8, Color = Color.White }; ComplexType complex2 = new ComplexType { Name = "Sep", Age = 9, Color = Color.Blue }; customersRead[0].ComplexCollection.Should().Equals(new List <ComplexType> { complex1, complex2 }); customersRead[0].EnumCollection.Should().Equals(new List <Color> { Color.White, Color.Blue }); }