Beispiel #1
0
    public static void BuildDispatcherWithConfiguration_Singleton_Not_WellKnown()
    {
        string serviceAddress = "http://localhost/dummy";
        var    services       = new ServiceCollection();

        services.AddServiceModelServices();
        var serverAddressesFeature = new ServerAddressesFeature();

        serverAddressesFeature.Addresses.Add(serviceAddress);
        IServer server = new MockServer();

        server.Features.Set <IServerAddressesFeature>(serverAddressesFeature);
        services.AddSingleton(server);
        var serviceProvider = services.BuildServiceProvider();
        var serviceBuilder  = serviceProvider.GetRequiredService <IServiceBuilder>();

        serviceBuilder.AddService <SimpleSingletonService>();
        var binding = new CustomBinding("BindingName", "BindingNS");

        binding.Elements.Add(new MockTransportBindingElement());
        serviceBuilder.AddServiceEndpoint <SimpleSingletonService, ISimpleService>(binding, serviceAddress);
        var dispatcherBuilder = serviceProvider.GetRequiredService <IDispatcherBuilder>();
        var dispatchers       = dispatcherBuilder.BuildDispatchers(typeof(SimpleSingletonService));

        Assert.Single(dispatchers);
        var dispatcher = dispatchers[0];

        Assert.Equal("foo", dispatcher.Binding.Scheme);
        Assert.Equal(serviceAddress, dispatcher.BaseAddress.ToString());
        var      requestContext = TestRequestContext.Create(serviceAddress);
        IChannel mockChannel    = new MockReplyChannel(serviceProvider);

        dispatcher.DispatchAsync(requestContext, mockChannel, CancellationToken.None).Wait();
        requestContext.ValidateReply();
    }
Beispiel #2
0
        public static void InstanceContextMode_Single()
        {
            SingleInstanceContextSimpleService.ClearCounts();
            var services        = new ServiceCollection();
            var serviceInstance = new SingleInstanceContextSimpleService();

            services.AddSingleton(serviceInstance);
            string   serviceAddress    = "http://localhost/dummy";
            var      serviceDispatcher = TestHelper.BuildDispatcher <SingleInstanceContextSimpleService>(services, serviceAddress);
            IChannel mockChannel       = new MockReplyChannel(services.BuildServiceProvider());
            var      dispatcher        = serviceDispatcher.CreateServiceChannelDispatcher(mockChannel);

            Assert.Equal(1, SingleInstanceContextSimpleService.AddBindingParametersCallCount);
            Assert.Equal(1, SingleInstanceContextSimpleService.ApplyDispatchBehaviorCount);
            Assert.Equal(1, SingleInstanceContextSimpleService.ValidateCallCount);

            var requestContext = TestRequestContext.Create(serviceAddress);

            dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait();
            requestContext = TestRequestContext.Create(serviceAddress);
            dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait();
            Assert.Equal(1, SingleInstanceContextSimpleService.CreationCount);
            Assert.Equal(0, SingleInstanceContextSimpleService.DisposalCount);
            Assert.Equal(2, serviceInstance.CallCount);
        }
Beispiel #3
0
        public static void InstanceContextMode_PerCall()
        {
            PerCallInstanceContextSimpleServiceAndBehavior.ClearCounts();
            var services = new ServiceCollection();

            services.AddTransient <PerCallInstanceContextSimpleServiceAndBehavior>();
            string   serviceAddress    = "http://localhost/dummy";
            var      serviceDispatcher = TestHelper.BuildDispatcher <PerCallInstanceContextSimpleServiceAndBehavior>(services, serviceAddress);
            IChannel mockChannel       = new MockReplyChannel(services.BuildServiceProvider());
            var      dispatcher        = serviceDispatcher.CreateServiceChannelDispatcher(mockChannel);

            // Instance created as part of service startup to probe if type is availale in DI
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.CreationCount);
            // Instance not disposed as it implements IServiceBehavior and is added to service behaviors
            Assert.Equal(0, PerCallInstanceContextSimpleServiceAndBehavior.DisposalCount);
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.AddBindingParametersCallCount);
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.ApplyDispatchBehaviorCount);
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.ValidateCallCount);

            PerCallInstanceContextSimpleServiceAndBehavior.ClearCounts();
            var requestContext = TestRequestContext.Create(serviceAddress);

            dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait();
            requestContext = TestRequestContext.Create(serviceAddress);
            dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait();
            Assert.Equal(2, PerCallInstanceContextSimpleServiceAndBehavior.CreationCount);
            Assert.Equal(2, PerCallInstanceContextSimpleServiceAndBehavior.DisposalCount);
        }
Beispiel #4
0
        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 static void BuildDispatcherAndCallService(ServiceCollection services)
        {
            string   serviceAddress    = "http://localhost/dummy";
            var      serviceDispatcher = BuildDispatcher <SimpleService>(services, serviceAddress);
            IChannel mockChannel       = new MockReplyChannel(services.BuildServiceProvider());
            var      dispatcher        = serviceDispatcher.CreateServiceChannelDispatcher(mockChannel);
            var      requestContext    = TestRequestContext.Create(serviceAddress);

            dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait();
        }
Beispiel #7
0
        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.");
        }
Beispiel #9
0
        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.");
        }
Beispiel #10
0
        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.");
        }
Beispiel #11
0
        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 BeginReceiveRequest_Calls_BeginReceiveRequest_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.BeginReceiveRequest(timeout, null, null);
            Assert.IsTrue(innerChannel.BeginReceiveRequestCalled, "HttpMessageEncodingReplyChannel.BeginReceiveRequest should call BeginReceiveRequest on the inner channel.");
            Assert.AreEqual(timeout, innerChannel.TimeoutParameter, "HttpMessageEncodingReplyChannel.BeginReceiveRequest should have passed the timeout parameter to the inner channel.");
            Assert.AreSame(innerChannel.AsyncResultReturned, result, "HttpMessageEncodingReplyChannel.BeginReceiveRequest should have returned the async result from the inner channel.");
        }
Beispiel #13
0
        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.");
        }
Beispiel #14
0
        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.");
        }
Beispiel #15
0
        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.");
        }
Beispiel #16
0
        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.");
        }
Beispiel #17
0
        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.");
        }
Beispiel #18
0
        public static void BuildDispatcherWithConfiguration_XmlSerializer()
        {
            var serviceAddress = "http://localhost/dummy";

            var services = new ServiceCollection();

            services.AddLogging();
            services.AddServiceModelServices();

            var serverAddressesFeature = new ServerAddressesFeature();

            serverAddressesFeature.Addresses.Add(serviceAddress);

            IServer server = new MockServer();

            server.Features.Set <IServerAddressesFeature>(serverAddressesFeature);
            services.AddSingleton(server);

            var serviceProvider = services.BuildServiceProvider();
            var serviceBuilder  = serviceProvider.GetRequiredService <IServiceBuilder>();

            serviceBuilder.AddService <SimpleXmlSerializerService>();

            var binding = new CustomBinding("BindingName", "BindingNS");

            binding.Elements.Add(new MockTransportBindingElement());
            serviceBuilder.AddServiceEndpoint <SimpleXmlSerializerService, ISimpleXmlSerializerService>(binding, serviceAddress);

            var dispatcherBuilder = serviceProvider.GetRequiredService <IDispatcherBuilder>();
            var dispatchers       = dispatcherBuilder.BuildDispatchers(typeof(SimpleXmlSerializerService));

            Assert.Single(dispatchers);

            var serviceDispatcher = dispatchers[0];

            Assert.Equal("foo", serviceDispatcher.Binding.Scheme);
            Assert.Equal(serviceAddress, serviceDispatcher.BaseAddress.ToString());

            IChannel mockChannel    = new MockReplyChannel(serviceProvider);
            var      dispatcher     = serviceDispatcher.CreateServiceChannelDispatcherAsync(mockChannel).Result;
            var      requestContext = XmlSerializerTestRequestContext.Create(serviceAddress);

            dispatcher.DispatchAsync(requestContext).Wait();
            Assert.True(requestContext.WaitForReply(TimeSpan.FromSeconds(5)), "Dispatcher didn't send reply");
            requestContext.ValidateReply();
        }
Beispiel #19
0
        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.");
        }
Beispiel #20
0
        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.");
        }
Beispiel #21
0
        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.");
        }
Beispiel #22
0
        public static void InstanceContextMode_PerCall_NoInjection()
        {
            PerCallInstanceContextSimpleService.ClearCounts();
            var      services          = new ServiceCollection();
            string   serviceAddress    = "http://localhost/dummy";
            var      serviceDispatcher = TestHelper.BuildDispatcher <PerCallInstanceContextSimpleService>(services, serviceAddress);
            IChannel mockChannel       = new MockReplyChannel(services.BuildServiceProvider());
            var      dispatcher        = serviceDispatcher.CreateServiceChannelDispatcher(mockChannel);

            // Instance shouldn't be created as part of service startup as type isn't available in DI
            Assert.Equal(0, PerCallInstanceContextSimpleService.CreationCount);
            Assert.Equal(0, PerCallInstanceContextSimpleService.DisposalCount);

            var requestContext = TestRequestContext.Create(serviceAddress);

            dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait();
            requestContext = TestRequestContext.Create(serviceAddress);
            dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait();
            Assert.Equal(2, PerCallInstanceContextSimpleService.CreationCount);
            Assert.Equal(2, PerCallInstanceContextSimpleService.DisposalCount);
        }
        public static void BuildDispatcherWithConfiguration_Singleton_WellKnown()
        {
            string serviceAddress = "http://localhost/dummy";
            var    services       = new ServiceCollection();

            services.AddLogging();
            services.AddServiceModelServices();
            IServer server = new MockServer();

            services.AddSingleton(server);
            services.AddSingleton(new SimpleSingletonService());
            services.AddSingleton(typeof(ILogger <>), typeof(NullLogger <>));
            services.RegisterApplicationLifetime();
            ServiceProvider serviceProvider = services.BuildServiceProvider();
            IServiceBuilder serviceBuilder  = serviceProvider.GetRequiredService <IServiceBuilder>();

            serviceBuilder.BaseAddresses.Add(new Uri(serviceAddress));
            serviceBuilder.AddService <SimpleSingletonService>();
            var binding = new CustomBinding("BindingName", "BindingNS");

            binding.Elements.Add(new MockTransportBindingElement());
            serviceBuilder.AddServiceEndpoint <SimpleSingletonService, ISimpleService>(binding, serviceAddress);
            serviceBuilder.OpenAsync().GetAwaiter().GetResult();
            IDispatcherBuilder dispatcherBuilder = serviceProvider.GetRequiredService <IDispatcherBuilder>();

            System.Collections.Generic.List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(typeof(SimpleSingletonService));
            Assert.Single(dispatchers);
            IServiceDispatcher serviceDispatcher = dispatchers[0];

            Assert.Equal("foo", serviceDispatcher.Binding.Scheme);
            Assert.Equal(serviceAddress, serviceDispatcher.BaseAddress.ToString());
            IChannel mockChannel = new MockReplyChannel(serviceProvider);
            IServiceChannelDispatcher dispatcher = serviceDispatcher.CreateServiceChannelDispatcherAsync(mockChannel).Result;
            var requestContext = TestRequestContext.Create(serviceAddress);

            dispatcher.DispatchAsync(requestContext).Wait();
            Assert.True(requestContext.WaitForReply(TimeSpan.FromSeconds(5)), "Dispatcher didn't send reply");
            requestContext.ValidateReply();
        }
        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 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 TryReceiveRequest_Returns_Null_If_Inner_Channel_Returns_Null()
        {
            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 = null;
            innerChannel.TryReceiveRequestReturnsTrue = true;
            RequestContext context;
            bool didRecievedRequest = channel.TryReceiveRequest(timeout, out context);
            Assert.IsNull(context, "HttpMessageEncodingReplyChannel.TryReceiveRequest should have returned null since the inner channel returned null.");
            Assert.IsTrue(didRecievedRequest, "HttpMessageEncodingReplyChannel.EndWaitForRequest should have returned the value returned from the inner channel.");
        }
        public void TryReceiveRequest_Calls_TryReceiveRequest_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();
            innerChannel.TryReceiveRequestReturnsTrue = true;
            RequestContext context;
            bool didRecievedRequest = channel.TryReceiveRequest(timeout, out context);
            Assert.IsTrue(innerChannel.TryReceiveRequestCalled, "HttpMessageEncodingReplyChannel.TryReceiveRequest should call TryReceiveRequest on the inner channel.");
            Assert.AreEqual(timeout, innerChannel.TimeoutParameter, "HttpMessageEncodingReplyChannel.TryReceiveRequest should have passed the timeout parameter to the inner channel.");
            Assert.IsInstanceOfType(context, typeof(HttpMessageEncodingRequestContext), "HttpMessageEncodingReplyChannel.ReceiveRequest should have returned an HttpMessageEncodingRequestContext instance.");
            Assert.IsTrue(didRecievedRequest, "HttpMessageEncodingReplyChannel.EndWaitForRequest should have returned the value returned from 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 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 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 EndTryReceiveRequest_Returns_Null_If_The_Inner_Channel_Returns_Null()
        {
            MockChannelListener channelManager = new MockChannelListener();
            MockReplyChannel innerChannel = new MockReplyChannel(channelManager);
            HttpMessageEncodingReplyChannel channel = new HttpMessageEncodingReplyChannel(channelManager, innerChannel);
            channel.Open();

            innerChannel.RequestContextToReturn = null;
            innerChannel.TryReceiveRequestReturnsTrue = true;
            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 null.");
        }
        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 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.");
        }