public void ParsingInstanceAnnotationsInTopLevelPropertyShouldSkipBaseOnSettings() { var model = this.CreateEdmModelWithEntity(); var primitiveTypeRef = ((IEdmEntityType)model.SchemaElements.First()).Properties().First().Type; ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"@odata.context\":\"http://odata.org/test/$metadata#Customers(1)/Name\",\"@Annotation.1\":true,\"@Annotation.2\":123,\"@Annotation.3\":\"annotation\",\"value\":\"Joe\"}", model)); ODataProperty property = deserializer.ReadTopLevelProperty(primitiveTypeRef); property.InstanceAnnotations.Count.Should().Be(0); }
public void ParsingInstanceAnnotationInTopLevelPropertyShouldThrowOnReservedODataAnnotationNamesNotApplicableToProperties() { var model = this.CreateEdmModelWithEntity(); var primitiveTypeRef = ((IEdmEntityType)model.SchemaElements.First()).Properties().First().Type; this.messageReaderSettings = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") }; ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"@odata.context\":\"http://odata.org/test/$metadata#Customers(1)/Name\",\"@odata.count\":123,\"value\":\"Joe\"}", model)); Action action = () => deserializer.ReadTopLevelProperty(primitiveTypeRef); action.ShouldThrow<ODataException>().WithMessage(ErrorStrings.ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties("odata.count")); }
public void ParsingInstanceAnnotationsInTopLevelPropertyShouldReadProperty() { var model = this.CreateEdmModelWithEntity(); var primitiveTypeRef = ((IEdmEntityType)model.SchemaElements.First()).Properties().First().Type; this.messageReaderSettings = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") }; ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"@odata.context\":\"http://odata.org/test/$metadata#Customers(1)/Name\",\"@Annotation.1\":true,\"@Annotation.2\":123,\"@Annotation.3\":\"annotation\",\"value\":\"Joe\"}", model)); ODataProperty property = deserializer.ReadTopLevelProperty(primitiveTypeRef); property.InstanceAnnotations.Count.Should().Be(3); TestUtils.AssertODataValueAreEqual(new ODataPrimitiveValue(true), property.InstanceAnnotations.Single(ia => ia.Name == "Annotation.1").Value); TestUtils.AssertODataValueAreEqual(new ODataPrimitiveValue(123), property.InstanceAnnotations.Single(ia => ia.Name == "Annotation.2").Value); TestUtils.AssertODataValueAreEqual(new ODataPrimitiveValue("annotation"), property.InstanceAnnotations.Single(ia => ia.Name == "Annotation.3").Value); }
/// <summary> /// This method creates an reads the property from the input and /// returns an <see cref="ODataProperty"/> representing the read property. /// </summary> /// <param name="property">The <see cref="IEdmProperty"/> producing the property to be read.</param> /// <param name="expectedPropertyTypeReference">The expected type reference of the property to read.</param> /// <returns>An <see cref="ODataProperty"/> representing the read property.</returns> public override ODataProperty ReadProperty(IEdmStructuralProperty property, IEdmTypeReference expectedPropertyTypeReference) { this.AssertSynchronous(); this.VerifyCanReadProperty(); ODataJsonLightPropertyAndValueDeserializer jsonLightPropertyAndValueDeserializer = new ODataJsonLightPropertyAndValueDeserializer(this); return jsonLightPropertyAndValueDeserializer.ReadTopLevelProperty(expectedPropertyTypeReference); }