public void ApplyProperty_DoesNotIgnoreKeyProperty() { // Arrange ODataProperty property = new ODataProperty { Name = "Key1", Value = "Value1" }; EdmEntityType entityType = new EdmEntityType("namespace", "name"); entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string)))); EdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false); ODataDeserializerProvider provider = new DefaultODataDeserializerProvider(); var resource = new Mock <IDelta>(MockBehavior.Strict); Type propertyType = typeof(string); resource.Setup(r => r.TryGetPropertyType("Key1", out propertyType)).Returns(true).Verifiable(); resource.Setup(r => r.TrySetPropertyValue("Key1", "Value1")).Returns(true).Verifiable(); // Act DeserializationHelpers.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext { IsPatchMode = true }); // Assert resource.Verify(); }
/// <summary> /// Deserializes the given <paramref name="complexValue"/> under the given <paramref name="readContext"/>. /// </summary> /// <param name="complexValue">The complex value to deserialize.</param> /// <param name="complexType">The EDM type of the complex value to read.</param> /// <param name="readContext">The deserializer context.</param> /// <returns>The deserialized complex value.</returns> public virtual object ReadComplexValue(ODataComplexValue complexValue, IEdmComplexTypeReference complexType, ODataDeserializerContext readContext) { if (complexValue == null) { throw Error.ArgumentNull("complexValue"); } if (readContext == null) { throw Error.ArgumentNull("readContext"); } if (readContext.Model == null) { throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext); } object complexResource = CreateResource(complexType, readContext); foreach (ODataProperty complexProperty in complexValue.Properties) { DeserializationHelpers.ApplyProperty(complexProperty, complexType, complexResource, DeserializerProvider, readContext); } return(complexResource); }
/// <summary> /// Deserializes the given <paramref name="structuralProperty"/> into <paramref name="entityResource"/>. /// </summary> /// <param name="entityResource">The object into which the structural property should be read.</param> /// <param name="structuralProperty">The entry object containing the structural properties.</param> /// <param name="readContext">The deserializer context.</param> public virtual void ApplyStructuralProperty(object entityResource, ODataProperty structuralProperty, ODataDeserializerContext readContext) { if (entityResource == null) { throw Error.ArgumentNull("entityResource"); } if (structuralProperty == null) { throw Error.ArgumentNull("structuralProperty"); } DeserializationHelpers.ApplyProperty(structuralProperty, EntityType, entityResource, DeserializerProvider, readContext); }