Ejemplo n.º 1
0
 public void IsUnknownODataAnnotationNameShouldReturnFalseOnReservedODataAnnotationName()
 {
     foreach (string annotationName in ReservedODataAnnotationNames)
     {
         ODataAnnotationNames.IsUnknownODataAnnotationName(annotationName).Should().BeFalse();
     }
 }
        /// <summary>
        /// Writes all the instance annotations specified in <paramref name="instanceAnnotations"/>.
        /// </summary>
        /// <param name="instanceAnnotations">Collection of instance annotations to write.</param>
        /// <param name="tracker">The tracker to track if instance annotations are written.</param>
        /// <param name="ignoreFilter">Whether to ignore the filter in settings.</param>
        /// <param name="propertyName">The name of the property this instance annotation applies to</param>
        internal void WriteInstanceAnnotations(
            IEnumerable <ODataInstanceAnnotation> instanceAnnotations,
            InstanceAnnotationWriteTracker tracker,
            bool ignoreFilter   = false,
            string propertyName = null)
        {
            Debug.Assert(instanceAnnotations != null, "instanceAnnotations should not be null if we called this");
            Debug.Assert(tracker != null, "tracker should not be null if we called this");

            HashSet <string> instanceAnnotationNames = new HashSet <string>(StringComparer.Ordinal);

            foreach (var annotation in instanceAnnotations)
            {
                if (!instanceAnnotationNames.Add(annotation.Name))
                {
                    throw new ODataException(ODataErrorStrings.JsonLightInstanceAnnotationWriter_DuplicateAnnotationNameInCollection(annotation.Name));
                }

                if (!tracker.IsAnnotationWritten(annotation.Name) &&
                    (!ODataAnnotationNames.IsODataAnnotationName(annotation.Name) || ODataAnnotationNames.IsUnknownODataAnnotationName(annotation.Name)))
                {
                    this.WriteInstanceAnnotation(annotation, ignoreFilter, propertyName);
                    tracker.MarkAnnotationWritten(annotation.Name);
                }
            }
        }
Ejemplo n.º 3
0
 public void IsUnknownODataAnnotationNameShouldReturnFalseOnCustomAnnotationName()
 {
     ODataAnnotationNames.IsUnknownODataAnnotationName("custom.annotation").Should().BeFalse();
     foreach (string annotationName in ReservedODataAnnotationNames)
     {
         // We match the "odata." namespace case sensitive.
         ODataAnnotationNames.IsUnknownODataAnnotationName(annotationName.ToUpperInvariant()).Should().BeFalse();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Write instance annotation if not already written.
        /// </summary>
        /// <param name="annotation">The instance annotation to write.</param>
        /// <param name="tracker">The tracker to track if instance annotations are written.</param>
        /// <param name="instanceAnnotationNames">Set used to detect a duplicate annotation.</param>
        /// <param name="ignoreFilter">Whether to ignore the filter in settings.</param>
        /// <param name="propertyName">The name of the property this instance annotation applies to.</param>
        private void WriteAndTrackInstanceAnnotation(
            ODataInstanceAnnotation annotation,
            InstanceAnnotationWriteTracker tracker,
            HashSet <string> instanceAnnotationNames,
            bool ignoreFilter   = false,
            string propertyName = null)
        {
            if (!instanceAnnotationNames.Add(annotation.Name))
            {
                throw new ODataException(ODataErrorStrings.JsonLightInstanceAnnotationWriter_DuplicateAnnotationNameInCollection(annotation.Name));
            }

            if (!tracker.IsAnnotationWritten(annotation.Name) &&
                (!ODataAnnotationNames.IsODataAnnotationName(annotation.Name) || ODataAnnotationNames.IsUnknownODataAnnotationName(annotation.Name)))
            {
                this.WriteInstanceAnnotation(annotation, ignoreFilter, propertyName);
                tracker.MarkAnnotationWritten(annotation.Name);
            }
        }
Ejemplo n.º 5
0
 public void IsUnknownODataAnotationNameShouldReturnTrueOnUnknownODataAnnotationName()
 {
     ODataAnnotationNames.IsUnknownODataAnnotationName("odata.unknown").Should().BeTrue();
 }
Ejemplo n.º 6
0
 public void IsUnknownODataAnnotationNameShouldReturnFalseOnPropertyName()
 {
     ODataAnnotationNames.IsUnknownODataAnnotationName("odataPropertyName").Should().BeFalse();
 }
Ejemplo n.º 7
0
 public void IsUnknownODataAnotationNameShouldReturnTrueOnUnknownODataAnnotationName()
 {
     Assert.True(ODataAnnotationNames.IsUnknownODataAnnotationName("odata.unknown"));
 }
Ejemplo n.º 8
0
 public void IsUnknownODataAnnotationNameShouldReturnFalseOnPropertyName()
 {
     Assert.False(ODataAnnotationNames.IsUnknownODataAnnotationName("odataPropertyName"));
 }