private string WriteAndGetPayload(EdmModel edmModel, string contentType, Action <ODataMessageWriter> test)
        {
            var message = new InMemoryMessage()
            {
                Stream = new MemoryStream()
            };

            if (contentType != null)
            {
                message.SetHeader("Content-Type", contentType);
            }

            ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings();

            writerSettings.EnableMessageStreamDisposal = false;
            writerSettings.BaseUri = new Uri("http://www.example.com/");
            writerSettings.SetServiceDocumentUri(new Uri("http://www.example.com/"));

            using (var msgWriter = new ODataMessageWriter((IODataResponseMessage)message, writerSettings, edmModel))
            {
                test(msgWriter);
            }

            message.Stream.Seek(0, SeekOrigin.Begin);
            using (StreamReader reader = new StreamReader(message.Stream))
            {
                contentType = message.GetHeader("Content-Type");
                return(reader.ReadToEnd());
            }
        }
        public void GetHeaderOnInnerMessagePicksUpSetHeaderFromOuterCallOnWriting()
        {
            const string headerName        = "CustomHeaderName";
            const string headerValueBefore = "CustomerHeaderValueBefore";
            const string headerValueAfter  = "CustomerHeaderValueAfter";

            var simulatedRequestMessage = new InMemoryMessage {
                Method = "GET", Url = new Uri("http://example.com/Customers")
            };

            simulatedRequestMessage.SetHeader(headerName, headerValueBefore);

            var odataRequestMessage = new ODataRequestMessage(simulatedRequestMessage, true, false, -1);

            odataRequestMessage.SetHeader(headerName, headerValueAfter);

            Assert.Equal(headerValueAfter, simulatedRequestMessage.GetHeader(headerName));
        }