/// <summary> /// Verify that the type attribute of relationship link is not null and has the expected value "application/xml". /// </summary> /// <param name="link">The navigation link to verify.</param> /// <param name="request">The request needed for error report.</param> /// <param name="response">The response needed for error report.</param> private void VerifyAtomAssociationLinkTypeAttribute(ODataPayloadElement link, ODataRequest request, ODataResponse response) { ContentTypeAnnotation typeAnnotation = link.Annotations.OfType <ContentTypeAnnotation>().SingleOrDefault(); string expectedTypeAttributeValue = "application/xml"; if (typeAnnotation == null || string.Compare(typeAnnotation.Value, expectedTypeAttributeValue, StringComparison.CurrentCulture) != 0) { this.Logger.WriteLine(LogLevel.Verbose, CultureInfo.InvariantCulture, "Expected relationship link type attribute '{0}', observed '{1}'", expectedTypeAttributeValue, typeAnnotation == null ? "null" : typeAnnotation.Value); this.ReportFailure(request, response); throw new ResponseVerificationException(); } }
/// <summary> /// Verify that the type attribute of navigation link is not null and has the expected value. /// </summary> /// <param name="link">The relationship link to verify.</param> /// <param name="request">The request needed for error report.</param> /// <param name="response">The response needed for error report.</param> private void VerifyAtomNavigationLinkTypeAttribute(ODataPayloadElement link, ODataRequest request, ODataResponse response) { ContentTypeAnnotation typeAnnotation = link.Annotations.OfType <ContentTypeAnnotation>().SingleOrDefault(); if (typeAnnotation == null || (!typeAnnotation.Value.Equals("application/atom+xml;type=feed", StringComparison.Ordinal) && !typeAnnotation.Value.Equals("application/atom+xml;type=entry", StringComparison.Ordinal))) { this.Logger.WriteLine(LogLevel.Verbose, CultureInfo.InvariantCulture, "Expected navigation link type attribute application/atom+xml;type=feed or application/atom+xml;type=entry, observed '{0}'", typeAnnotation == null ? "null" : typeAnnotation.Value); this.ReportFailure(request, response); throw new ResponseVerificationException(); } }
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); } }