Exemple #1
0
        private string WriteAndVerifyCarEntry(ODataMessageWriterSettings settings, string mimeType, bool hasModel)
        {
            // create a car entry
            var carEntry = WritePayloadHelper.CreateCarEntryNoMetadata(hasModel);

            carEntry.MediaResource = new ODataStreamReferenceValue();

            Dictionary <string, object> expectedCarObject = WritePayloadHelper.ComputeExpectedFullMetadataEntryObject(WritePayloadHelper.CarType, "Car(11)", carEntry, hasModel);

            WritePayloadHelper.ComputeDefaultExpectedFullMetadataEntryMedia(WritePayloadHelper.CarType, "Car(11)", carEntry, expectedCarObject, true /*hasStream*/, hasModel);

            // write the response message and read using ODL reader
            var responseMessage = new StreamResponseMessage(new MemoryStream());

            responseMessage.SetHeader("Content-Type", mimeType);
            responseMessage.PreferenceAppliedHeader().AnnotationFilter = "foo.*";
            string result = string.Empty;

            using (var messageWriter = this.CreateODataMessageWriter(responseMessage, settings, hasModel))
            {
                var odataWriter = this.CreateODataEntryWriter(messageWriter, WritePayloadHelper.CarSet, WritePayloadHelper.CarType, hasModel);
                odataWriter.WriteStart(carEntry);
                odataWriter.WriteEnd();

                result = this.ReadFeedEntryMessage(false, responseMessage, mimeType, WritePayloadHelper.CarSet, WritePayloadHelper.CarType);
            }

            // For Json light, verify the resulting metadata is as expected
            if (mimeType != MimeTypes.ApplicationAtomXml)
            {
                JavaScriptSerializer        jScriptSerializer = new JavaScriptSerializer();
                Dictionary <string, object> resultObject      = jScriptSerializer.DeserializeObject(result) as Dictionary <string, object>;

                VerifyODataContextAnnotation(this.ServiceUri + "$metadata#Car/$entity", resultObject, mimeType);

                VerifyEntry(expectedCarObject, carEntry, new ODataNavigationLink[] { }, new ODataProperty[] { }, resultObject, mimeType, settings.AutoComputePayloadMetadataInJson);
            }

            return(result);
        }