/// <summary>
        /// Called to write the payload to the specified <paramref name="messageWriter"/>.
        /// </summary>
        /// <param name="messageWriter">The <see cref="ODataMessageWriterTestWrapper"/> to use for writing the payload.</param>
        /// <param name="testConfiguration">The test configuration to generate the payload for.</param>
        protected override void WritePayload(ODataMessageWriterTestWrapper messageWriter, WriterTestConfiguration testConfiguration)
        {
            ODataPayloadElement payload = this.PayloadElement.DeepCopy();

            if (testConfiguration.Format == ODataFormat.Json)
            {
                payload.Accept(new ODataPayloadJsonNormalizer());
                //Fixup added as odatalib requires ids on feeds even though it can't be represented in json
                payload.Accept(new AddFeedIDFixup());
            }
            else if (testConfiguration.Format == ODataFormat.Atom)
            {
                // TODO: Remove visitor
                payload.Accept(new ODataPayloadElementNullIDVisitor());
            }

            ODataPayloadElementToObjectModelConverter converter = new ODataPayloadElementToObjectModelConverter(!testConfiguration.IsRequest);

            if (this.PayloadKind != ODataPayloadKind.Batch)
            {
                this.settings.ObjectModelToMessageWriter.WriteMessage(messageWriter, this.PayloadKind, converter.Convert(payload));
            }
            else
            {
                TestWriterUtils.WriteBatchPayload(messageWriter,
                                                  payload,
                                                  converter,
                                                  this.settings.ObjectModelToMessageWriter,
                                                  this.Model,
                                                  this.settings.Assert,
                                                  testConfiguration,
                                                  true);
            }
        }
        /// <summary>
        /// Verifies the result of the write-read.
        /// </summary>
        /// <param name="message">The test message is not used but is required to keep the method signature the same.</param>
        /// <param name="payloadKind">The payload kind is not used but is required to keep the method signature the same.</param>
        /// <param name="testConfiguration">The test configuration is used for some fixups.</param>
        public override void VerifyResult(TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger = null)
        {
            //TODO: Use Logger to verify result, right now this change is only to unblock writer testcase checkin

            Debug.Assert(ObservedElement != null, "ObservedElement not provided");
            // Fixup the expected and get the content type
            ODataPayloadElement expected = this.ExpectedPayload.DeepCopy();
            ODataPayloadElement observed = this.ObservedElement.DeepCopy();

            observed.Accept(new RemoveTypeNameAnnotationFromComplexInCollection());
            expected.Accept(new ReorderProperties());
            expected.Accept(new RemoveComplexWithNoProperties());

            // Compare
            this.settings.PayloadElementComparer.Compare(expected, observed);
        }
 /// <summary>
 /// The base for recursing a property to write a property using ODataMessageWriter
 /// </summary>
 /// <param name="writer">The message writer to use for writing the property</param>
 /// <param name="payload">The payload to be written as a property</param>
 public void WriteProperty(ODataMessageWriter writer, ODataPayloadElement payload)
 {
     this.writer = writer;
     payload.Accept(this);
     ExceptionUtilities.CheckObjectNotNull(this.odataProperties, "ODataProperty cannot be null");
     ExceptionUtilities.Assert(this.odataProperties.Count == 1, "There can be only one property left when writing the result");
     this.writer.WritePropertyAsync(this.odataProperties.First()).Wait();
     this.odataProperties.Clear();
 }
 private string JsonFixup(ODataPayloadElement payload)
 {
     // We have removed all the annotations except for Self Link which also we can remove since it shows up as ID and 
     // convert primitives to expected JSON representations
     payload.Accept(new ODataPayloadJsonNormalizer());
     payload.Accept(new RemoveFeedIDFixup());
     payload.Accept(new ReorderProperties());
     payload.Accept(new ODataPayloadElementNullTypenameVisitor());
     payload.Accept(new RemoveMLEAnnotation());
     payload.Accept(new RemoveAnnotations());
     payload.Accept(new JsonSelfLinkToEditLinkFixup());
     payload.Accept(new RemoveExpandedLinkUriStringVisitor());
     return MimeTypes.ApplicationJson;
 }
 private string JsonFixup(ODataPayloadElement payload)
 {
     // We have removed all the annotations except for Self Link which also we can remove since it shows up as ID and
     // convert primitives to expected JSON representations
     payload.Accept(new ODataPayloadJsonNormalizer());
     payload.Accept(new RemoveFeedIDFixup());
     payload.Accept(new ReorderProperties());
     payload.Accept(new ODataPayloadElementNullTypenameVisitor());
     payload.Accept(new RemoveMLEAnnotation());
     payload.Accept(new RemoveAnnotations());
     payload.Accept(new JsonSelfLinkToEditLinkFixup());
     payload.Accept(new RemoveExpandedLinkUriStringVisitor());
     return(MimeTypes.ApplicationJson);
 }
        /// <summary>
        /// The base for recursing a property to write a property using ODataMessageWriter
        /// </summary>
        /// <param name="writer">The message writer to use for writing the property</param>
        /// <param name="payload">The payload to be written as a property</param>
        public void WriteProperty(ODataMessageWriter writer, ODataPayloadElement payload)
        {
            this.writer = writer;
            payload.Accept(this);
            ExceptionUtilities.CheckObjectNotNull(this.odataProperties, "ODataProperty cannot be null");
            ExceptionUtilities.Assert(this.odataProperties.Count == 1, "There can be only one property left when writing the result");
#if SILVERLIGHT 
            this.writer.WriteProperty(this.odataProperties.First());
#else
            this.writer.WritePropertyAsync(this.odataProperties.First()).Wait();
#endif
            this.odataProperties.Clear();
        }
        /// <summary>
        /// Calculates the Protocol Version based on the payloadElement provided
        /// </summary>
        /// <param name="payloadElement">Payload Element</param>
        /// <param name="contentType">Content Type</param>
        /// <param name="maxProtocolVersion">The max protocol version</param>
        /// <param name="maxDataServiceVersion">The max data service version of the request</param>
        /// <returns>Data Service protocol version</returns>
        public DataServiceProtocolVersion CalculateProtocolVersion(ODataPayloadElement payloadElement, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
            ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType");
            ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified");

            this.responseContentType          = contentType;
            this.version                      = DataServiceProtocolVersion.V4;
            this.currentMaxProtocolVersion    = maxProtocolVersion;
            this.currentMaxDataServiceVersion = maxDataServiceVersion;

            payloadElement.Accept(this);
            return(this.version);
        }
        /// <summary>
        /// Calculates the Protocol Version based on the payloadElement provided
        /// </summary>
        /// <param name="payloadElement">Payload Element</param>
        /// <param name="contentType">Content Type</param>
        /// <param name="maxProtocolVersion">The max protocol version</param>
        /// <param name="maxDataServiceVersion">The max data service version of the request</param>
        /// <returns>Data Service protocol version</returns>
        public DataServiceProtocolVersion CalculateProtocolVersion(ODataPayloadElement payloadElement, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
            ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType");
            ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified");

            this.responseContentType = contentType;
            this.version = DataServiceProtocolVersion.V4;
            this.currentMaxProtocolVersion = maxProtocolVersion;
            this.currentMaxDataServiceVersion = maxDataServiceVersion;

            payloadElement.Accept(this);
            return this.version;
        }
示例#9
0
            private void Recurse(ODataPayloadElement element)
            {
                ExceptionUtilities.CheckArgumentNotNull(element, "element");
                var preformatted = element.Annotations.OfType <RawTextPayloadElementRepresentationAnnotation>().SingleOrDefault();

                if (preformatted != null)
                {
                    this.writer.WriteRaw(preformatted.Text);
                }
                else
                {
                    element.Accept(this);
                }
            }
            private void WrapAccept(ODataPayloadElement expected, ODataPayloadElement observed)
            {
                ExceptionUtilities.CheckArgumentNotNull(expected, "expected");
                ExceptionUtilities.CheckArgumentNotNull(observed, "observed");

                this.observedElementStack.Push(observed);
                try
                {
                    expected.Accept(this);
                }
                finally
                {
                    this.observedElementStack.Pop();
                }
            }
示例#11
0
        private static string WriteToStream(ODataFormat format, Action <ODataPayloadElement> writeToStream, ODataPayloadElement payload)
        {
            string contentType = null;

            if (format == ODataFormat.Json)
            {
                payload.Accept(new ODataPayloadJsonNormalizer());
                contentType = MimeTypes.ApplicationJsonLight;
            }
            else
            {
                ExceptionUtilities.Assert(format == ODataFormat.Atom, "Format not supported: {0}", format);
                contentType = MimeTypes.ApplicationAtomXml;
            }

            writeToStream(payload);
            return(contentType);
        }
示例#12
0
 private string AtomFixup(ODataPayloadElement payload)
 {
     // We have removed all the annotations except for Self Link which also we can remove since it shows up as ID and
     // convert primitives to expected JSON representations
     // TODO: Remove visitor
     payload.Accept(new ODataPayloadElementNullIDVisitor());
     payload.Accept(new AddExpandedLinkMetadata());
     payload.Accept(new ODataPayloadElementAddDefaultAtomMetadata());
     payload.Accept(new ODataPayloadElementNullTypenameVisitor());
     payload.Accept(new NullStringTypenameFixup());
     payload.Accept(new RemoveAnnotations());
     return(MimeTypes.ApplicationAtomXml);
 }
示例#13
0
 private string AtomFixup(ODataPayloadElement payload)
 {
     // We have removed all the annotations except for Self Link which also we can remove since it shows up as ID and 
     // convert primitives to expected JSON representations
     // TODO: Remove visitor
     payload.Accept(new ODataPayloadElementNullIDVisitor());
     payload.Accept(new AddExpandedLinkMetadata());
     payload.Accept(new ODataPayloadElementAddDefaultAtomMetadata());
     payload.Accept(new ODataPayloadElementNullTypenameVisitor());
     payload.Accept(new NullStringTypenameFixup());
     payload.Accept(new RemoveAnnotations());
     return MimeTypes.ApplicationAtomXml;
 }
        private void VisitPayloadElement(ODataPayloadElement payloadElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
            if (this.TryAttachXmlRepresentation(payloadElement))
            {
                return;
            }

            this.payloadStack.Push(payloadElement);

            try
            {
                payloadElement.Accept(this);
            }
            finally
            {
                this.payloadStack.Pop();
            }
        }
 /// <summary>
 /// Removes annotations on the payload element and initiates the Visitor pattern.
 /// </summary>
 /// <param name="payloadElement">The payload element to remove annotations from.</param>
 public void RemoveAnnotations(ODataPayloadElement payloadElement)
 {
     payloadElement.RemoveAnnotations(typeof(T));
     payloadElement.Accept(this);
 }
 public ODataPayloadElement Normalize(ODataPayloadElement payloadElement)
 {
     return payloadElement.Accept(this);
 }
示例#17
0
 public ODataPayloadElement Normalize(ODataPayloadElement payloadElement)
 {
     return(payloadElement.Accept(this));
 }
 /// <summary>
 /// Normalizes the given payload root
 /// </summary>
 /// <param name="rootElement">The payload to normalize</param>
 /// <returns>The normalized payload</returns>
 public virtual ODataPayloadElement Normalize(ODataPayloadElement rootElement)
 {
     return rootElement.Accept(this);
 }
 private void Recurse(ODataPayloadElement element)
 {
     ExceptionUtilities.CheckArgumentNotNull(element, "element");
     var preformatted = element.Annotations.OfType<RawTextPayloadElementRepresentationAnnotation>().SingleOrDefault();
     if (preformatted != null)
     {
         this.writer.WriteRaw(preformatted.Text);
     }
     else
     {
         element.Accept(this);
     }
 }
 public void Validate(ODataPayloadElement payloadElement)
 {
     ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
     payloadElement.Accept(this);
 }
示例#21
0
 public object Convert(ODataPayloadElement payload)
 {
     this.items.Clear();
     payload.Accept(this);
     return(items.SingleOrDefault());
 }
示例#22
0
 private string DefaultFixup(ODataPayloadElement payload)
 {
     payload.Accept(new ExpectedBatchPayloadFixup());
     return MimeTypes.MultipartMixed;
 }
 /// <summary>
 /// Normalizes the given payload root
 /// </summary>
 /// <param name="rootElement">The payload to normalize</param>
 /// <returns>The normalized payload</returns>
 public virtual ODataPayloadElement Normalize(ODataPayloadElement rootElement)
 {
     return(rootElement.Accept(this));
 }
示例#24
0
        private static string WriteToStream(ODataFormat format, Action<ODataPayloadElement> writeToStream, ODataPayloadElement payload)
        {
            string contentType = null;
            if (format == ODataFormat.Json)
            {
                payload.Accept(new ODataPayloadJsonNormalizer());
                contentType = MimeTypes.ApplicationJsonLight;
            }
            else
            {
                ExceptionUtilities.Assert(format == ODataFormat.Atom, "Format not supported: {0}", format);
                contentType = MimeTypes.ApplicationAtomXml;
            }

            writeToStream(payload);
            return contentType;
        }
            /// <summary>
            /// Validates a payload with the given root element against the given expected value
            /// </summary>
            /// <param name="rootElement">The root element of the payload</param>
            /// <param name="expected">The expected value</param>
            public void Validate(ODataPayloadElement rootElement, QueryValue expected)
            {
                ExceptionUtilities.CheckArgumentNotNull(rootElement, "rootElement");
                ExceptionUtilities.CheckArgumentNotNull(expected, "expected");

                this.expectedValueStack.Push(expected);
                this.payloadStack.Push(rootElement);

                rootElement.Accept(this);
            }
示例#26
0
 private string DefaultFixup(ODataPayloadElement payload)
 {
     payload.Accept(new ExpectedBatchPayloadFixup());
     return(MimeTypes.MultipartMixed);
 }
 private void Recurse(ODataPayloadElement element, QueryValue value)
 {
     this.expectedValueStack.Push(value);
     this.payloadStack.Push(element);
     try
     {
         element.Accept(this);
     }
     finally
     {
         this.expectedValueStack.Pop();
         this.payloadStack.Pop();
     }
 }
 public object Convert(ODataPayloadElement payload)
 {
     this.items.Clear();
     payload.Accept(this);
     return items.SingleOrDefault();
 }