private bool CompareAnnotation(ODataPayloadElementAnnotation expectedAnnotation, ODataPayloadElementAnnotation observedAnnotation, out string errorMessage)
        {
            try
            {
                errorMessage = null;
                this.Assert.AreEqual(expectedAnnotation.GetType(), observedAnnotation.GetType(), "Annotation types should be same");
                if (expectedAnnotation is XmlTreeAnnotation)
                {
                    XmlTreeAnnotation e = expectedAnnotation as XmlTreeAnnotation;
                    XmlTreeAnnotation o = observedAnnotation as XmlTreeAnnotation;
                    this.Assert.IsNotNull(o, "Observed annotation cannot be null");
                    this.Assert.AreEqual(e.LocalName, o.LocalName, "Local names should match");
                    this.Assert.AreEqual(e.NamespaceName, o.NamespaceName, "Namespace names should be equal");
                    this.Assert.AreEqual(e.PropertyValue, o.PropertyValue, "Property values must be equal");
                    this.Assert.AreEqual(e.IsAttribute, o.IsAttribute, "IsAttribute values should be equal");
                    this.Assert.AreEqual(e.Children.Count, o.Children.Count, "Children count must be equal");
                    Compare(e.Children.Cast<ODataPayloadElementAnnotation>().ToList(), o.Children.Cast<ODataPayloadElementAnnotation>().ToList());
                }
                else if (expectedAnnotation is SelfLinkAnnotation)
                {
                    SelfLinkAnnotation e = expectedAnnotation as SelfLinkAnnotation;
                    SelfLinkAnnotation o = observedAnnotation as SelfLinkAnnotation;
                    this.Assert.IsNotNull(o, "Observed annotation cannot be null");
                    this.Assert.AreEqual(e.Value, o.Value, "Values should match");
                }
                else if (expectedAnnotation is ContentTypeAnnotation)
                {
                    ContentTypeAnnotation e = expectedAnnotation as ContentTypeAnnotation;
                    ContentTypeAnnotation o = observedAnnotation as ContentTypeAnnotation;
                    this.Assert.IsNotNull(o, "Observed annotation cannot be null");
                    this.Assert.AreEqual(e.Value, o.Value, "Values should match");
                }

                return true;
            }
            catch (DataComparisonException e)
            {
                errorMessage = "Message: " + e.Message + " Exception type:" + e.GetType() + " Stack:" + e.StackTrace;
                return false;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Adds an annotation to the specified ODataPayloadElement
 /// </summary>
 /// <typeparam name="TElement">The type of the payload element to work on.</typeparam>
 /// <param name="element">The payload element to annotate</param>
 /// <param name="annotation">The annotation</param>
 /// <returns>The annotated payload element, for composability</returns>
 private static TElement AddAnnotation <TElement>(this TElement element, ODataPayloadElementAnnotation annotation) where TElement : ODataPayloadElement
 {
     element.Annotations.Add(annotation);
     return(element);
 }