示例#1
0
 public void Client()
 {
     using (var server = new TcpRpcServer())
         using (var client = new TcpRpcClient())
         {
             Assert.IsFalse(client.IsComputing);
             Assert.IsFalse(client.IsWaitingForData);
             Assert.AreEqual(0L, client.SendCount);
             Assert.AreEqual(0L, client.RecvCount);
             Assert.ThrowsException <InvalidOperationException>(() => client.GetMain <ITestInterface>());
             Assert.ThrowsException <ArgumentNullException>(() => client.AttachTracer(null));
             Assert.ThrowsException <ArgumentNullException>(() => client.InjectMidlayer(null));
             (var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
             server.StartAccepting(addr, port);
             client.Connect(addr.ToString(), port);
             Assert.ThrowsException <InvalidOperationException>(() => client.Connect(addr.ToString(), port));
             Assert.IsTrue(client.WhenConnected.Wait(MediumNonDbgTimeout));
             Assert.ThrowsException <InvalidOperationException>(() => client.AttachTracer(new FrameTracing.RpcFrameTracer(Console.Out, false)));
             Assert.ThrowsException <InvalidOperationException>(() => client.InjectMidlayer(_ => _));
             Assert.AreEqual(port, client.RemotePort);
             Assert.IsTrue(client.LocalPort != 0);
             Assert.AreEqual(0L, client.SendCount);
             Assert.AreEqual(0L, client.RecvCount);
             Assert.IsTrue(SpinWait.SpinUntil(() => client.IsWaitingForData, MediumNonDbgTimeout));
             ((IConnection)client).Close();
             Assert.IsTrue(SpinWait.SpinUntil(() => client.State == ConnectionState.Down, MediumNonDbgTimeout));
         }
 }
示例#2
0
        protected static TcpRpcClient SetupClient(IPAddress addr, int port, TcpRpcTestOptions options = TcpRpcTestOptions.None)
        {
            var client = new TcpRpcClient();

            client.AddBuffering();
            if (options.HasFlag(TcpRpcTestOptions.ClientTracer))
            {
                client.AttachTracer(new FrameTracing.RpcFrameTracer(Console.Out, false));
            }
            if (options.HasFlag(TcpRpcTestOptions.ClientFluctStream))
            {
                client.InjectMidlayer(s => new FluctStream(s));
            }
            if (!options.HasFlag(TcpRpcTestOptions.ClientNoConnect))
            {
                client.Connect(addr.ToString(), port);
            }
            return(client);
        }