public void MessageState_Is_Closed_After_Calling_Closed()
        {
            HttpRequestMessage request = new HttpRequestMessage();
            HttpMessage        message = new HttpMessage(request);

            message.Close();
            Assert.AreEqual(MessageState.Closed, message.State, "HttpMessage.State should be MessageState.Closed.");
        }
Example #2
0
        public void Closing_Disposes_Of_The_HttpResponseMessage()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            response.Content = new ByteArrayContent(new byte[0]);
            HttpMessage message = new HttpMessage(response);
            message.Close();
            Assert.AreEqual(MessageState.Closed, message.State, "HttpMessage.State should be closed.");

            ExceptionAssert.ThrowsObjectDisposed(
                typeof(ByteArrayContent).FullName,
                () =>
                {
                    response.Content.ReadAsByteArray();
                });
        }
        public void Closing_Disposes_Of_The_HttpResponseMessage()
        {
            HttpResponseMessage response = new HttpResponseMessage();

            response.Content = new ByteArrayContent(new byte[0]);
            HttpMessage message = new HttpMessage(response);

            message.Close();
            Assert.AreEqual(MessageState.Closed, message.State, "HttpMessage.State should be closed.");

            ExceptionAssert.Throws(
                typeof(ObjectDisposedException),
                "HttpRequestMessage.Content.ReadAsByteArray should have thrown because the HttpResponseMessage was disposed.",
                () =>
            {
                response.Content.ReadAsByteArray();
            });
        }
        public void WriteMessage_Throws_If_The_Message_State_Is_Not_Created()
        {
            HttpMessageEncoderFactory factory = new HttpMessageEncoderFactory();
            MessageEncoder            encoder = factory.Encoder;

            HttpResponseMessage response = new HttpResponseMessage();

            response.Content = new ByteArrayContent(new byte[5] {
                0, 1, 2, 3, 4
            });
            HttpMessage message = new HttpMessage(response);

            message.Close();

            ExceptionAssert.Throws(
                typeof(InvalidOperationException),
                "HttpMessageEncoder.WriteMessage should have thrown since the message state was not MessageState.Created.",
                () =>
            {
                encoder.WriteMessage(message, 5, new MockBufferManager());
            });
        }
        public void Reply_Throws_If__Message_Is_Closed()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            HttpMessage message = new HttpMessage(response);
            message.Close();

            MockRequestContext innerRequestContext = new MockRequestContext();
            HttpMessageEncodingRequestContext requestContext = new HttpMessageEncodingRequestContext(innerRequestContext);

            ExceptionAssert.Throws<ObjectDisposedException>(
                SR.MessageClosed,
                () =>
                {
                    requestContext.Reply(message);
                });
        }
Example #6
0
 public void MessageState_Is_Closed_After_Calling_Closed()
 {
     HttpRequestMessage request = new HttpRequestMessage();
     HttpMessage message = new HttpMessage(request);
     message.Close();
     Assert.AreEqual(MessageState.Closed, message.State, "HttpMessage.State should be MessageState.Closed.");
 }