Пример #1
0
        /// <summary>
        /// Compares the actual function import against the expected.
        /// </summary>
        /// <param name="expectedFunctionImport">expected function import</param>
        /// <param name="actualFunctionImport">actual import</param>
        /// <remarks>This implementation also compares the annotations on the function import.</remarks>
        protected override void CompareFunctionImport(FunctionImport expectedFunctionImport, FunctionImport actualFunctionImport)
        {
            // TODO: Add support for checking annotations to the EntityModelSchemaComparer.CompareFunctionImport method.
            // We have overridden the base method because we wanted to minimize the impact of this change to other existing Taupo test cases.
            base.CompareFunctionImport(expectedFunctionImport, actualFunctionImport);

            if (!this.WriteErrorIfFalse(
                    expectedFunctionImport.Annotations.OfType <AttributeAnnotation>().Count() == actualFunctionImport.Annotations.OfType <AttributeAnnotation>().Count(),
                    "Expected and actual count of the FunctionImport annotations did not match."))
            {
                // verify annotations
                foreach (AttributeAnnotation expectedAnnotation in expectedFunctionImport.Annotations.OfType <AttributeAnnotation>())
                {
                    AttributeAnnotation actualAnnotation = actualFunctionImport.Annotations.OfType <AttributeAnnotation>().SingleOrDefault(
                        ann => ann.Content.Name.Equals(expectedAnnotation.Content.Name));

                    if (!this.WriteErrorIfFalse(actualAnnotation != null, "The expected annotation named '{0}' was not found in the FunctionImport.", expectedAnnotation.Content.Name.LocalName))
                    {
                        this.WriteErrorIfFalse(
                            actualAnnotation.Content.Value == expectedAnnotation.Content.Value,
                            "FunctionImport annotation not equal. Expected {0}, Actual: {1}",
                            expectedAnnotation.Content.Value,
                            actualAnnotation.Content.Value);
                    }
                }
            }
        }
Пример #2
0
        private Annotation ConvertSingleAnnotation(AttributeAnnotation annotation)
        {
            if (annotation.Content == null)
            {
                return(annotation);
            }

            if (annotation.Content.Name.Namespace == EdmConstants.AnnotationNamespace && annotation.Content.Name.LocalName == "StoreGeneratedPattern")
            {
                if (annotation.Content.Value == StoreGeneratedPatternAnnotation.None.Name)
                {
                    return(StoreGeneratedPatternAnnotation.None);
                }
                else if (annotation.Content.Value == StoreGeneratedPatternAnnotation.Identity.Name)
                {
                    return(StoreGeneratedPatternAnnotation.Identity);
                }
                else
                {
                    ExceptionUtilities.Assert(annotation.Content.Value == StoreGeneratedPatternAnnotation.Computed.Name, "Unrecognized store generated annotation: '{0}'", annotation.Content.Value);
                    return(StoreGeneratedPatternAnnotation.Computed);
                }
            }

            if (annotation.Content.Name.Namespace != EdmConstants.TaupoAnnotationsNamespace)
            {
                return(annotation);
            }

            Type annotationType = this.FindAnnotationType(annotation.Content.Name);

            if (annotationType == null)
            {
                return(annotation);
            }

            // if the type can do custom serialization...
            if (typeof(ICustomAnnotationSerializer).IsAssignableFrom(annotationType))
            {
                // since this interface is implemented, we also expect a constructor
                // which takes an XAttribute to be there, so let's just invoke it
                // on our XAttribute
                return((Annotation)Activator.CreateInstance(annotationType, annotation.Content));
            }

            // if it is a tag, just create instance of that class
            if (typeof(TagAnnotation).IsAssignableFrom(annotationType))
            {
                return((Annotation)Activator.CreateInstance(annotationType));
            }

            // otherwise return the original
            return(annotation);
        }
        private static void AddAnnotationIfDoesntExist(AnnotatedItem payload, AttributeAnnotation annotation)
        {
            var exists = payload.Annotations.OfType <AttributeAnnotation>().Any(a =>
            {
                ExceptionUtilities.CheckObjectNotNull(a.Content, "Content expected for attribute");
                return(a.Content.Name.Equals(annotation.Content.Name));
            });

            if (!exists)
            {
                payload.Annotations.Add(annotation);
            }
        }
Пример #4
0
 /// <summary>
 /// Adds an unconditionally compiled source code element to a sequence of conditionally compiled elements.
 /// </summary>
 /// <param name="sequence">The sequence append to</param>
 /// <param name="element">The element to append</param>
 public static void Add(this RepeatedField <ConditionalAttributeAnnotation> sequence, AttributeAnnotation element) => sequence.Add(new ConditionalAttributeAnnotation()
 {
     Element = element
 });