public void AfterReceiveRequest_Null_HttpRequestMessage_Throws()
 {
     IDispatchMessageInspector inspector = new MockHttpMessageInspector();
     Message wcfMessage = Message.CreateMessage(MessageVersion.None, "unused"); ;
     IClientChannel channel = new MockClientChannel();
     InstanceContext context = new InstanceContext(new MockService1());
     ExceptionAssert.ThrowsInvalidOperation(
         "Message without HttpRequestMessage should throw",
         () =>
         {
             inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
         });
 }
 public void AfterReceiveRequest_Null_Message_Throws()
 {
     IDispatchMessageInspector inspector = new MockHttpMessageInspector();
     Message wcfMessage = null;
     IClientChannel channel = new MockClientChannel();
     InstanceContext context = new InstanceContext(new MockService1());
     ExceptionAssert.ThrowsArgumentNull(
         "Null WCF message argument should throw",
         "request",
         () =>
         {
             inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
         });
 }
        public void AfterReceiveRequest_Receives_HttpRequestMessage()
        {
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage();
            Message wcfMessage = httpRequestMessage.ToMessage();
            IClientChannel channel = new MockClientChannel();
            InstanceContext context = new InstanceContext(new MockService1());

            IDispatchMessageInspector inspector = new MockHttpMessageInspector()
            {
                OnAfterReceiveRequest = actualMessage =>
                {
                    Assert.AreSame(httpRequestMessage, actualMessage, "AfterReceiveRequest did not receive the HttpRequestMessage");
                    return /*state*/ null;
                }
            };

            inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
            Assert.IsTrue(((MockHttpMessageInspector)inspector).WasAfterReceiveRequestCalled, "AfterReceiveRequest in derived class was not called");
        }
        public void AfterReceiveRequest_Returns_Custom_State_Value()
        {
            string stringInstance = "hello";
            Message wcfMessage = new HttpRequestMessage().ToMessage();
            IClientChannel channel = new MockClientChannel();
            InstanceContext context = new InstanceContext(new MockService1());

            IDispatchMessageInspector inspector = new MockHttpMessageInspector()
            {
                OnAfterReceiveRequest = actualMessage =>
                {
                    return stringInstance;
                }
            };

            object returnedValue = inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
            Assert.IsTrue(((MockHttpMessageInspector)inspector).WasAfterReceiveRequestCalled, "AfterReceiveRequest in derived class was not called");
            Assert.AreSame(stringInstance,
                           returnedValue,
                           "AfterReceiveRequest return value is not the one we returned.");
        }
        public void BeforeSendReply_Receives_HttpResponseMessage()
        {
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
            Message wcfMessage = httpResponseMessage.ToMessage();

            IDispatchMessageInspector inspector = new MockHttpMessageInspector()
            {
                OnBeforeSendReply = (actualMessage, state) =>
                {
                    Assert.AreSame(httpResponseMessage, actualMessage, "BeforeSendReply did not receive the message we provided.");
                }
            };

            inspector.BeforeSendReply(ref wcfMessage, correlationState: null);
            Assert.AreSame(httpResponseMessage, wcfMessage.ToHttpResponseMessage(), "Expected embedded HttpResponseMessage to remain unmodified");
            Assert.IsTrue(((MockHttpMessageInspector)inspector).WasBeforeSendReplyCalled, "BeforeSentReply in derived class was not called");
        }
        public void BeforeSendReply_Receives_Custom_CorrelationState()
        {
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
            Message wcfMessage = httpResponseMessage.ToMessage();
            object correlationState = "Hello";

            IDispatchMessageInspector inspector = new MockHttpMessageInspector()
            {
                OnBeforeSendReply = (actualMessage, state) =>
                {
                    Assert.AreSame(correlationState, state, "BeforeSendReply did not receive the state we provided.");
                }
            };

            inspector.BeforeSendReply(ref wcfMessage, correlationState);
            Assert.IsTrue(((MockHttpMessageInspector)inspector).WasBeforeSendReplyCalled, "BeforeSentReply in derived class was not called");
        }
 public void BeforeSendReply_Null_Message_Throws()
 {
     IDispatchMessageInspector inspector = new MockHttpMessageInspector();
     Message wcfMessage = null;
     ExceptionAssert.ThrowsArgumentNull(
         "Null message argument should throw",
         "reply",
         () =>
         {
             inspector.BeforeSendReply(ref wcfMessage, correlationState: null);
         });
 }
 public void BeforeSendReply_Null_HttpResponseMessage_Throws()
 {
     IDispatchMessageInspector inspector = new MockHttpMessageInspector();
     Message wcfMessage = Message.CreateMessage(MessageVersion.None, "unused");
     ExceptionAssert.ThrowsInvalidOperation(
         "WCF message without inner Http message should throw",
         () =>
         {
             inspector.BeforeSendReply(ref wcfMessage, correlationState: null);
         });
 }