Esempio n. 1
0
        public async Task ByLineMessagesOverSocketsTest()
        {
            var serverListener = new TcpListener(IPAddress.Loopback, TcpLocalTestPort);

            serverListener.Start();
            try
            {
                using (var tcpClient = new TcpClient())
                {
                    var serverAsync = serverListener.AcceptTcpClientAsync();
                    await tcpClient.ConnectAsync(IPAddress.Loopback, TcpLocalTestPort);

                    using (var tcpServer = await serverAsync)
                        using (var ss = tcpServer.GetStream())
                            using (var cs = tcpClient.GetStream())
                            {
                                using (var clientReader = new ByLineTextMessageReader(cs))
                                    using (var clientWriter = new ByLineTextMessageWriter(cs))
                                        using (var serverReader = new ByLineTextMessageReader(ss))
                                            using (var serverWriter = new ByLineTextMessageWriter(ss))
                                                using (var server = new ServerTestHelper(this, serverReader, serverWriter,
                                                                                         StreamRpcServerHandlerOptions.None))
                                                    using (var client = new ClientTestHelper(clientReader, clientWriter))
                                                        using (var server1 = new ServerTestHelper(this, clientReader, clientWriter,
                                                                                                  StreamRpcServerHandlerOptions.None))
                                                            using (var client1 = new ClientTestHelper(serverReader, serverWriter))
                                                            {
                                                                async Task ClientTestAsync()
                                                                {
                                                                    await Task.Yield();

                                                                    await TestRoutines.TestStubAsync(client.ClientStub);

                                                                    await TestRoutines.TestStubAsync(client.ClientExceptionStub);
                                                                }
                                                                async Task Client1TestAsync()
                                                                {
                                                                    await Task.Yield();

                                                                    await TestRoutines.TestStubAsync(client1.ClientStub);

                                                                    await TestRoutines.TestStubAsync(client1.ClientExceptionStub);
                                                                }

                                                                await Task.WhenAll(ClientTestAsync(), Client1TestAsync());
                                                            }
                            }
                }
            }
            finally
            {
                serverListener.Stop();
            }
        }
 public async Task PartwiseStreamCancellationTest()
 {
     (var ss, var cs) = FullDuplexStream.CreatePair();
     using (var clientReader = new ByLineTextMessageReader(cs))
         using (var clientWriter = new ByLineTextMessageWriter(cs))
             using (var serverReader = new ByLineTextMessageReader(ss))
                 using (var serverWriter = new ByLineTextMessageWriter(ss))
                     using (var server = new ServerTestHelper(this, serverReader, serverWriter,
                                                              StreamRpcServerHandlerOptions.SupportsRequestCancellation))
                         using (var client = new ClientTestHelper(clientReader, clientWriter))
                         {
                             await TestRoutines.TestCancellationAsync(client.ClientCancellationStub);
                         }
 }
Esempio n. 3
0
        public async Task ClientInteropTest()
        {
            var host = Utility.CreateJsonRpcServiceHost(this);

            using (var handler = new HttpRpcClientHandler(new JsonRpcHttpMessageDirectHandler(host))
            {
                EndpointUrl = "http://localhost:1234/fakepath"
            })
            {
                var client  = new JsonRpcClient(handler);
                var builder = new JsonRpcProxyBuilder {
                    ContractResolver = Utility.DefaultContractResolver
                };
                var stub1 = builder.CreateProxy <ITestRpcContract>(client);
                var stub2 = builder.CreateProxy <ITestRpcExceptionContract>(client);
                await TestRoutines.TestStubAsync(stub1);

                await TestRoutines.TestStubAsync(stub2);
            }
        }
        public async Task PartwiseStreamInteropTest()
        {
            (var ss, var cs) = FullDuplexStream.CreatePair();
            using (var clientReader = new ByLineTextMessageReader(cs))
                using (var clientWriter = new ByLineTextMessageWriter(cs))
                    using (var serverReader = new ByLineTextMessageReader(ss))
                        using (var serverWriter = new ByLineTextMessageWriter(ss))
                            using (var server = new ServerTestHelper(this, serverReader, serverWriter,
                                                                     StreamRpcServerHandlerOptions.None))
                                using (var client = new ClientTestHelper(clientReader, clientWriter))
                                {
                                    var e = Assert.Raises <MessageEventArgs>(h => client.ClientHandler.MessageSending += h,
                                                                             h => client.ClientHandler.MessageSending -= h,
                                                                             () => client.ClientStub.One());
                                    Assert.Equal("one", ((RequestMessage)e.Arguments.Message).Method);
                                    e = Assert.Raises <MessageEventArgs>(h => client.ClientHandler.MessageReceiving += h,
                                                                         h => client.ClientHandler.MessageReceiving -= h,
                                                                         () => client.ClientStub.One());
                                    Assert.Equal(new JValue(1), ((ResponseMessage)e.Arguments.Message).Result);
                                    await TestRoutines.TestStubAsync(client.ClientStub);

                                    await TestRoutines.TestStubAsync(client.ClientExceptionStub);
                                }
        }
Esempio n. 5
0
 public async Task ProxyExceptionTest()
 {
     var proxy = proxyBuilder.CreateProxy <ITestRpcExceptionContract>(client);
     await TestRoutines.TestStubAsync(proxy);
 }