public void ProxyPassesOnTokenToMethod_WhenTimeoutsNotIgnored() { var expectedResult = "test"; var classToProxy = new CancellableWithTimeoutPreserved(expectedResult); var proxy = CommandInterceptor.CreateProxy<ICancellableTimeoutPreserved>(classToProxy); // If we pass a valid token to the proxy then it should pass the token to the method call. var token = new CancellationTokenSource(500).Token; var result = proxy.CancellableMethod(token); Assert.True(classToProxy.CallMade); Assert.Equal(classToProxy.TokenRecievedFromProxy, token); Assert.Equal(expectedResult, result); }
public void ProxyPassesOnTokenToMethod_WhenTimeoutsNotIgnored() { var expectedResult = "test"; var classToProxy = new CancellableWithTimeoutPreserved(expectedResult); var proxy = CommandInterceptor.CreateProxy <ICancellableTimeoutPreserved>(classToProxy); // If we pass a valid token to the proxy then it should pass the token to the method call. var token = new CancellationTokenSource(500).Token; var result = proxy.CancellableMethod(token); Assert.True(classToProxy.CallMade); Assert.Equal(classToProxy.TokenRecievedFromProxy, token); Assert.Equal(expectedResult, result); }
public void ProxyPassesATimeoutTokenToMethod_WhenTimeoutsNotIgnored() { var expectedResult = "test"; var classToProxy = new CancellableWithTimeoutPreserved(expectedResult); var proxy = CommandInterceptor.CreateProxy<ICancellableTimeoutPreserved>(classToProxy); // If we pass CancellationToken.None to the proxy then it should pass a timeout tokem to the method call. var result = proxy.CancellableMethod(CancellationToken.None); Assert.True(classToProxy.CallMade && classToProxy.TokenReceivedFromProxy != CancellationToken.None); // This shouldn't be cancelled yet. Assert.False(classToProxy.TokenReceivedFromProxy.IsCancellationRequested); // Now sleep past the timeout. Thread.Sleep(CancellableWithTimeoutPreserved.Timeout + 50); Assert.True(classToProxy.TokenReceivedFromProxy.IsCancellationRequested); Assert.Equal(expectedResult, result); }
public void ProxyPassesATimeoutTokenToMethod_WhenTimeoutsNotIgnored() { var expectedResult = "test"; var classToProxy = new CancellableWithTimeoutPreserved(expectedResult); var proxy = CommandInterceptor.CreateProxy <ICancellableTimeoutPreserved>(classToProxy); // If we pass CancellationToken.None to the proxy then it should pass a timeout tokem to the method call. var result = proxy.CancellableMethod(CancellationToken.None); Assert.True(classToProxy.CallMade && classToProxy.TokenRecievedFromProxy != CancellationToken.None); // This shouldn't be cancelled yet. Assert.False(classToProxy.TokenRecievedFromProxy.IsCancellationRequested); // Now sleep past the timeout. Thread.Sleep(CancellableWithTimeoutPreserved.Timeout + 50); Assert.True(classToProxy.TokenRecievedFromProxy.IsCancellationRequested); Assert.Equal(expectedResult, result); }