public void Invoke_connects_and_invokes_method_with_result() { ConnectionManagerStub connectionManagerStub = new ConnectionManagerStub(); connectionManagerStub.Proxy = new MyProxyStub(); ProxyInvoker <IMyProxy> invoker = new ProxyInvoker <IMyProxy>(connectionManagerStub); object input = new object(); Task <object> task = invoker.InvokeAsync(p => p.DoAsync(input)); Assert.Equal(TaskStatus.RanToCompletion, task.Status); Assert.Same(input, task.Result); Assert.Equal(1, connectionManagerStub.ConnectCount); }
public void Invoke_connects_and_invokes_method_with_exception_and_invalidates() { ConnectionManagerStub connectionManagerStub = new ConnectionManagerStub(); MyProxyStub proxyStub = new MyProxyStub(); connectionManagerStub.Proxy = proxyStub; ProxyInvoker <IMyProxy> invoker = new ProxyInvoker <IMyProxy>(connectionManagerStub); InvalidTimeZoneException expectedException = new InvalidTimeZoneException("Expected."); proxyStub.Exception = expectedException; Task <object> task = invoker.InvokeAsync(p => p.DoAsync(new object())); Assert.Equal(TaskStatus.Faulted, task.Status); AggregateException ae = Assert.IsType <AggregateException>(task.Exception); Assert.Equal(1, ae.InnerExceptions.Count); Assert.Same(expectedException, ae.InnerExceptions[0]); Assert.Equal(1, connectionManagerStub.InvalidateCount); }
private static async Task RunClientAsync(Uri address, CancellationToken token) { ClientEventSource eventSource = ClientEventSource.Instance; NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); binding.OpenTimeout = TimeSpan.FromSeconds(1.0d); binding.SendTimeout = TimeSpan.FromSeconds(1.0d); binding.ReceiveTimeout = TimeSpan.FromSeconds(1.0d); binding.CloseTimeout = TimeSpan.FromSeconds(1.0d); CalculatorChannelFactory factory = new CalculatorChannelFactory(binding, new EndpointAddress(address), eventSource); await factory.OpenAsync(); ConnectionManager<ICalculatorClientAsync> connectionManager = new ConnectionManager<ICalculatorClientAsync>(factory); using (ProxyInvoker<ICalculatorClientAsync> proxy = new ProxyInvoker<ICalculatorClientAsync>(connectionManager)) { Random random = new Random(); while (!token.IsCancellationRequested) { try { await proxy.InvokeAsync(c => InvokeRandomAsync(random, c)); } catch (Exception) { } await Task.Delay(TimeSpan.FromMilliseconds(250.0d)); } } await factory.CloseAsync(); }