Exemple #1
0
        /// <summary>
        /// Set the response stream.
        /// </summary>
        /// <param name ="message">The message that we are setting the stream for.</param>
        /// <param name="stream">Stream to which the response needs to be written.</param>
        internal static void SetStream(this IODataResponseMessage message, Stream stream)
        {
            AstoriaResponseMessage             astoriaResponseMessage = message as AstoriaResponseMessage;
            ODataBatchOperationResponseMessage batchResponseMessage   = message as ODataBatchOperationResponseMessage;

            if (astoriaResponseMessage != null)
            {
                Debug.Assert(stream != null, "When we call SetStream on a non-batch response message, the stream shouldn't be null.");
                astoriaResponseMessage.SetStream(stream);
            }
            else if (batchResponseMessage != null)
            {
                Debug.Assert(stream == null, "When we call SetStream, if we are in a batch operation, then the stream should be null.");
            }
            else
            {
                Debug.Fail("SetStream called on an unknown message type.");
            }
        }
        public void ApplyCommonSettingsShouldDisableMessageStreamDisposalForTopLevel()
        {
            // AstoriaResponseMessage is only used for representing top-level responses, not individual parts of a batched response.
            var topLevelResponseMessage = new AstoriaResponseMessage(this.host);

            var testSubject = new ODataMessageWriterSettings { DisableMessageStreamDisposal = false };
            MessageWriterBuilder.ApplyCommonSettings(testSubject, new Uri("http://www.example.com"), VersionUtil.Version4Dot0, this.dataServiceSimulator, topLevelResponseMessage);
            testSubject.DisableMessageStreamDisposal.Should().BeTrue();
        }