public void OnlyCustomAnnotationsForPropertyAddedShouldReturnEmpty()
        {
            PropertyAndAnnotationCollector duplicateChecker = new PropertyAndAnnotationCollector(true);

            duplicateChecker.AddCustomPropertyAnnotation("property", "custom.annotation", "value");
            duplicateChecker.AddCustomPropertyAnnotation("property", "custom.annotation2", "value");
            duplicateChecker.GetODataPropertyAnnotations("property").Should().BeEmpty();
        }
        public void DuplicatePropertyCustomAnnotationShouldNotFail()
        {
            PropertyAndAnnotationCollector duplicateChecker = new PropertyAndAnnotationCollector(true);
            Action action = () => duplicateChecker.AddCustomPropertyAnnotation("property", "custom.name", "value");

            action.ShouldNotThrow();
            action.ShouldNotThrow();
        }
        public void MarkPropertyAsProcessedWithNoPropertyShouldWork()
        {
            PropertyAndAnnotationCollector duplicateChecker = new PropertyAndAnnotationCollector(true);

            duplicateChecker.MarkPropertyAsProcessed("property");
            Action odataAction = () => duplicateChecker.AddODataPropertyAnnotation("property", JsonLightConstants.ODataAnnotationNamespacePrefix + "name", "value");

            odataAction.ShouldThrow <ODataException>().WithMessage(ErrorStrings.PropertyAnnotationAfterTheProperty(JsonLightConstants.ODataAnnotationNamespacePrefix + "name", "property"));
            Action customAction = () => duplicateChecker.AddCustomPropertyAnnotation("property", "custom.name", "value");

            customAction.ShouldThrow <ODataException>().WithMessage(ErrorStrings.PropertyAnnotationAfterTheProperty("custom.name", "property"));
        }
Beispiel #4
0
 /// <summary>
 /// Reads built-in "odata." or custom instance annotation's value.
 /// </summary>
 /// <param name="annotatedPropertyName">The property name.</param>
 /// <param name="annotationName">The annotation name</param>
 /// <param name="propertyAndAnnotationCollector">The PropertyAndAnnotationCollector.</param>
 /// <param name="readPropertyAnnotationValue">Callback to read the property annotation value.</param>
 private void ReadODataOrCustomInstanceAnnotationValue(string annotatedPropertyName, string annotationName, PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func <string, object> readPropertyAnnotationValue)
 {
     // Read over the property name.
     this.JsonReader.Read();
     if (ODataJsonLightReaderUtils.IsODataAnnotationName(annotationName))
     {
         // OData annotations are read
         propertyAndAnnotationCollector.AddODataPropertyAnnotation(annotatedPropertyName, annotationName, readPropertyAnnotationValue(annotationName));
     }
     else
     {
         if (this.ShouldSkipCustomInstanceAnnotation(annotationName) || (this is ODataJsonLightErrorDeserializer && this.MessageReaderSettings.ShouldIncludeAnnotation == null))
         {
             propertyAndAnnotationCollector.CheckIfPropertyOpenForAnnotations(annotatedPropertyName, annotationName);
             this.JsonReader.SkipValue();
         }
         else
         {
             Debug.Assert(ReadPropertyCustomAnnotationValue != null, "readPropertyCustomAnnotationValue != null");
             propertyAndAnnotationCollector.AddCustomPropertyAnnotation(annotatedPropertyName, annotationName, ReadPropertyCustomAnnotationValue(propertyAndAnnotationCollector, annotationName));
         }
     }
 }