public void LocalAddress_Calls_LocalAdress_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            innerChannel.SetLocalAddress(new EndpointAddress("http://somehost.org"));
            Assert.AreSame(innerChannel.LocalAddress, channel.LocalAddress, "HttpMessageEncodingReplyChannel.LocalAddress should call LocalAddress on the inner channel.");
        }
        public void Abort_Calls_Abort_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            channel.Abort();
            Assert.IsTrue(innerChannel.OnAbortCalled, "HttpMessageEncodingReplyChannel.Abort should call Abort on the inner channel.");
        }
        public void EndOpen_Calls_EndOpen_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            IAsyncResult result = channel.BeginOpen(null, null);

            channel.EndOpen(result);
            Assert.IsTrue(innerChannel.OnEndOpenCalled, "HttpMessageEncodingReplyChannel.EndOpen should call EndOpen on the inner channel.");
        }
        public void BeginOpen_Calls_BeginOpen_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            TimeSpan     timeout = new TimeSpan(0, 1, 0);
            IAsyncResult result  = channel.BeginOpen(timeout, null, null);

            Assert.IsTrue(innerChannel.OnBeginOpenCalled, "HttpMessageEncodingReplyChannel.BeginOpen should call BeginOpen on the inner channel.");
            Assert.AreEqual(timeout, innerChannel.TimeoutParameter, "HttpMessageEncodingReplyChannel.BeginOpen should have passed the timeout parameter to the inner channel.");
        }
        public void ReceiveRequest_Returns_Null_If_Inner_Channel_Returns_Null()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            innerChannel.RequestContextToReturn = null;
            RequestContext context = channel.ReceiveRequest();

            Assert.IsNull(context, "HttpMessageEncodingReplyChannel.ReceiveRequest should have returned null since the inner channel returned null.");
        }
        public void EndWaitForRequest_Calls_EndWaitForRequest_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            innerChannel.RequestContextToReturn = new MockRequestContext();
            IAsyncResult result             = channel.BeginWaitForRequest(new TimeSpan(0, 1, 0), null, null);
            bool         didRecievedRequest = channel.EndWaitForRequest(result);

            Assert.IsTrue(innerChannel.EndWaitForRequestCalled, "HttpMessageEncodingReplyChannel.EndWaitForRequest should call EndWaitForRequest on the inner channel.");
            Assert.IsFalse(didRecievedRequest, "HttpMessageEncodingReplyChannel.EndWaitForRequest should have returned the value returned from the inner channel.");
        }
        public void BeginWaitForRequest_Calls_BeginWaitForRequest_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            TimeSpan     timeout = new TimeSpan(0, 1, 0);
            IAsyncResult result  = channel.BeginWaitForRequest(timeout, null, null);

            Assert.IsTrue(innerChannel.BeginWaitForRequestCalled, "HttpMessageEncodingReplyChannel.BeginWaitForRequest should call BeginWaitForRequest on the inner channel.");
            Assert.AreEqual(timeout, innerChannel.TimeoutParameter, "HttpMessageEncodingReplyChannel.BeginWaitForRequest should have passed the timeout parameter to the inner channel.");
            Assert.AreSame(innerChannel.AsyncResultReturned, result, "HttpMessageEncodingReplyChannel.BeginWaitForRequest should have returned the async result from the inner channel.");
        }
        public void WaitForRequest_Calls_WaitForRequest_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            TimeSpan timeout            = new TimeSpan(0, 1, 0);
            bool     didRecievedRequest = channel.WaitForRequest(timeout);

            Assert.IsTrue(innerChannel.WaitForRequestCalled, "HttpMessageEncodingReplyChannel.WaitForRequest should call WaitForRequest on the inner channel.");
            Assert.AreEqual(timeout, innerChannel.TimeoutParameter, "HttpMessageEncodingReplyChannel.WaitForRequest should have passed the timeout parameter to the inner channel.");
            Assert.IsFalse(didRecievedRequest, "HttpMessageEncodingReplyChannel.EndWaitForRequest should have returned the value returned from the inner channel.");
        }
        public void EndReceiveRequest_Calls_EndReceiveRequest_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            innerChannel.RequestContextToReturn = new MockRequestContext();
            IAsyncResult   result  = channel.BeginReceiveRequest(null, null);
            RequestContext context = channel.EndReceiveRequest(result);

            Assert.IsTrue(innerChannel.EndReceiveRequestCalled, "HttpMessageEncodingReplyChannel.EndReceiveRequest should call EndReceiveRequest on the inner channel.");
            Assert.IsInstanceOfType(context, typeof(HttpMessageEncodingRequestContext), "HttpMessageEncodingReplyChannel.EndReceiveRequest should have returned an HttpMessageEncodingRequestContext instance.");
        }
        public void EndTryReceiveRequest_Returns_Null_If_The_Inner_Channel_Returns_False()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            innerChannel.RequestContextToReturn       = new MockRequestContext();
            innerChannel.TryReceiveRequestReturnsTrue = false;
            IAsyncResult   result = channel.BeginTryReceiveRequest(new TimeSpan(0, 1, 0), null, null);
            RequestContext context;
            bool           didRecievedRequest = channel.EndTryReceiveRequest(result, out context);

            Assert.IsNull(context, "HttpMessageEncodingReplyChannel.EndTryReceiveRequest should have returned null since the inner channel returned false.");
        }
        public void ReceiveRequest_Calls_ReceiveRequest_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            TimeSpan timeout = new TimeSpan(0, 1, 0);

            innerChannel.RequestContextToReturn = new MockRequestContext();
            RequestContext context = channel.ReceiveRequest(timeout);

            Assert.IsTrue(innerChannel.ReceiveRequestCalled, "HttpMessageEncodingReplyChannel.ReceiveRequest should call ReceiveRequest on the inner channel.");
            Assert.AreEqual(timeout, innerChannel.TimeoutParameter, "HttpMessageEncodingReplyChannel.ReceiveRequest should have passed the timeout parameter to the inner channel.");
            Assert.IsInstanceOfType(context, typeof(HttpMessageEncodingRequestContext), "HttpMessageEncodingReplyChannel.ReceiveRequest should have returned an HttpMessageEncodingRequestContext instance.");
        }
        public void EndTryReceiveRequest_Calls_EndTryReceiveRequest_On_The_Inner_Channel()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            innerChannel.RequestContextToReturn       = new MockRequestContext();
            innerChannel.TryReceiveRequestReturnsTrue = true;
            IAsyncResult   result = channel.BeginTryReceiveRequest(new TimeSpan(0, 1, 0), null, null);
            RequestContext context;
            bool           didRecievedRequest = channel.EndTryReceiveRequest(result, out context);

            Assert.IsTrue(innerChannel.EndTryReceiveRequestCalled, "HttpMessageEncodingReplyChannel.EndTryReceiveRequest should call EndTryReceiveRequest on the inner channel.");
            Assert.IsTrue(didRecievedRequest, "HttpMessageEncodingReplyChannel.EndTryReceiveRequest should have returned the value returned from the inner channel.");
            Assert.IsInstanceOfType(context, typeof(HttpMessageEncodingRequestContext), "HttpMessageEncodingReplyChannel.EndTryReceiveRequest should have returned an HttpMessageEncodingRequestContext instance.");
        }
        public void TryReceiveRequest_Returns_Null_If_Inner_Channel_Returns_False()
        {
            MockChannelListener             channelManager = new MockChannelListener();
            MockReplyChannel                innerChannel   = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel        = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);

            channel.Open();

            TimeSpan timeout = new TimeSpan(0, 1, 0);

            innerChannel.RequestContextToReturn       = new MockRequestContext();
            innerChannel.TryReceiveRequestReturnsTrue = false;
            RequestContext context;
            bool           didRecievedRequest = channel.TryReceiveRequest(timeout, out context);

            Assert.IsNull(context, "HttpMessageEncodingReplyChannel.TryReceiveRequest should have returned null since the inner channel returned false.");
            Assert.IsFalse(didRecievedRequest, "HttpMessageEncodingReplyChannel.EndWaitForRequest should have returned the value returned from the inner channel.");
        }