private void WriteDeltaFeedAnnotationsAndValidatePayload(Action <ODataWriter> action, IEdmEntitySet entitySet, string expectedPayload)
        {
            var writerSettings = new ODataMessageWriterSettings {
                EnableMessageStreamDisposal = false
            };

            writerSettings.SetServiceDocumentUri(new Uri("http://www.example.com/"));

            MemoryStream stream = new MemoryStream();

            IODataResponseMessage responseMessageToWrite = new InMemoryMessage {
                StatusCode = 200, Stream = stream
            };

            responseMessageToWrite.PreferenceAppliedHeader().AnnotationFilter = "*";
            using (var messageWriter = new ODataMessageWriter(responseMessageToWrite, writerSettings, Model))
            {
                ODataWriter odataDeltaWriter = messageWriter.CreateODataDeltaResourceSetWriter(entitySet, EntityType);
                action(odataDeltaWriter);
            }

            stream.Position = 0;
            string payload = (new StreamReader(stream)).ReadToEnd();

            Assert.Equal(expectedPayload, payload);
        }
        /// <inheritdoc />
        public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
        {
            if (messageWriter == null)
            {
                throw Error.ArgumentNull("messageWriter");
            }

            if (writeContext == null)
            {
                throw Error.ArgumentNull("writeContext");
            }

            if (graph == null)
            {
                throw new SerializationException(Error.Format(SRResources.CannotSerializerNull, DeltaFeed));
            }

            IEdmEntitySetBase entitySet = writeContext.NavigationSource as IEdmEntitySetBase;

            if (entitySet == null)
            {
                throw new SerializationException(SRResources.EntitySetMissingDuringSerialization);
            }

            IEdmTypeReference feedType = writeContext.GetEdmType(graph, type);

            Contract.Assert(feedType != null);

            IEdmEntityTypeReference entityType = GetResourceType(feedType).AsEntity();

            ODataWriter writer = messageWriter.CreateODataDeltaResourceSetWriter(entitySet, entityType.EntityDefinition());

            WriteDeltaFeedInline(graph, feedType, writer, writeContext);
        }