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