public void UnaryCall()
        {
            RunWith10SecTimeout(async() =>
            {
                Console.WriteLine("Starting test");
                EchoRequest receivedRequest           = null;
                MethodCallContext receivedCallContext = null;

                Task <EchoRequest> HandleAsync(EchoRequest request, MethodCallContext context)
                {
                    receivedRequest     = request;
                    receivedCallContext = context;
                    return(Task.FromResult(request));
                }

                var client = ConnectEchoClient();
                ConnectEchoServer(x => x
                                  .WithProvidedService(
                                      "plexus.interop.testing.EchoService",
                                      s => s.WithUnaryMethod <EchoRequest, EchoRequest>("Unary", HandleAsync)
                                      )
                                  );
                var sentRequest = CreateTestRequest();
                Console.WriteLine("Starting call");
                var response = await client.CallInvoker.Call(EchoUnaryMethod, sentRequest);
                Console.WriteLine("Response received");
                receivedRequest.ShouldBe(sentRequest);
                response.ShouldBe(sentRequest);
                receivedCallContext.ShouldNotBeNull();
                receivedCallContext.ConsumerApplicationId.ShouldBe("plexus.interop.testing.EchoClient");
                receivedCallContext.ConsumerConnectionId.ShouldBe(client.ConnectionId);
            });
        }
        public void InvocationShouldBeRoutedToAnotherInstanceEvenIfSourceAppCanHandleIt()
        {
            MethodCallContext receivedRequestContext = null;

            Task <EchoRequest> HandleAsync(EchoRequest request, MethodCallContext context)
            {
                receivedRequestContext = context;
                return(Task.FromResult(request));
            }

            RunWith10SecTimeout(async() =>
            {
                var echoServerFactory = new TestClientFactory(
                    (broker, id) =>
                {
                    var optionsBuilder = new ClientOptionsBuilder()
                                         .WithBrokerWorkingDir(_testBrokerFixture.SharedInstance.WorkingDir)
                                         .WithDefaultConfiguration()
                                         .WithProvidedService(
                        EchoService.Id,
                        x => x.WithUnaryMethod <EchoRequest, EchoRequest>("Unary", HandleAsync))
                                         .WithApplicationId(EchoServerClient.Id);

                    return(ClientFactory.Instance.Create(optionsBuilder.Build()));
                });
                var appLauncher = RegisterDisposable(
                    new TestAppLauncher(
                        _testBrokerFixture.SharedInstance,
                        new Dictionary <string, TestClientFactory> {
                    { EchoServerClient.Id, echoServerFactory }
                }
                        )
                    );
                await appLauncher.StartAsync();
                var server   = ConnectEchoServer();
                var request  = CreateTestRequest();
                var response = await server.CallInvoker.Call(EchoUnaryMethod, request);
                response.ShouldBe(request);
                receivedRequestContext.ShouldNotBeNull();
                receivedRequestContext.ConsumerConnectionId.ShouldBe(server.ConnectionId);
            });
        }
        public void InvocationShouldBeRoutedToAnotherInstanceEvenIfSourceAppCanHandleIt()
        {
            MethodCallContext receivedRequestContext = null;

            Task <EchoRequest> HandleAsync(EchoRequest request, MethodCallContext context)
            {
                receivedRequestContext = context;
                return(Task.FromResult(request));
            }

            RunWith10SecTimeout(async() =>
            {
                var server = ConnectEchoServer();
                ConnectEchoServer(
                    b => b.WithProvidedService(
                        EchoService.Id,
                        x => x.WithUnaryMethod <EchoRequest, EchoRequest>("Unary", HandleAsync)));
                var request  = CreateTestRequest();
                var response = await server.CallInvoker.Call(EchoUnaryMethod, request);
                response.ShouldBe(request);
                receivedRequestContext.ShouldNotBeNull();
                receivedRequestContext.ConsumerConnectionId.ShouldBe(server.ConnectionId);
            });
        }