public async Task ProducesImplementationThatProxiesMethodsToISingleClientProxyAsync() { var clientProxy = new MockSingleClientProxy(); var typedProxy = TypedClientBuilder <ITestClient> .Build(clientProxy); var objArg = new object(); var task = typedProxy.GetValue(1008, objArg, "test"); Assert.False(task.IsCompleted); Assert.Collection(clientProxy.Sends, send => { Assert.Equal("GetValue", send.Method); Assert.Collection(send.Arguments, arg1 => Assert.Equal(1008, arg1), arg2 => Assert.Same(objArg, arg2), arg3 => Assert.Same("test", arg3)); Assert.Equal(CancellationToken.None, send.CancellationToken); send.Complete(); }); var result = await task.DefaultTimeout(); Assert.Equal(default(int), result); }
public async Task ResultMethodSupportsCancellationToken() { var clientProxy = new MockSingleClientProxy(); var typedProxy = TypedClientBuilder <ICancellationTokenMethod> .Build(clientProxy); CancellationTokenSource cts1 = new CancellationTokenSource(); var task1 = typedProxy.MethodReturning("foo", cts1.Token); Assert.False(task1.IsCompleted); CancellationTokenSource cts2 = new CancellationTokenSource(); var task2 = typedProxy.NoArgumentMethodReturning(cts2.Token); Assert.False(task2.IsCompleted); Assert.Collection(clientProxy.Sends, send1 => { Assert.Equal("MethodReturning", send1.Method); Assert.Single(send1.Arguments); Assert.Collection(send1.Arguments, arg1 => Assert.Equal("foo", arg1)); Assert.Equal(cts1.Token, send1.CancellationToken); send1.Complete(); }, send2 => { Assert.Equal("NoArgumentMethodReturning", send2.Method); Assert.Empty(send2.Arguments); Assert.Equal(cts2.Token, send2.CancellationToken); send2.Complete(); }); var result = await task1.DefaultTimeout(); Assert.Equal(default(string), result); var result2 = await task2.DefaultTimeout(); Assert.Equal(default(int), result2); }