public void Cancellation() { var cancel = new CancellationTokenSource(); cancel.CancelAfter(100); int updateCalled = 0; var operation = new TestOperation <int>("operation-id", TimeSpan.FromMilliseconds(1000), 100, null) { UpdateCalled = () => { updateCalled++; } }; Assert.That(async() => { _ = await operation.WaitForCompletionAsync(cancel.Token); }, Throws.InstanceOf <OperationCanceledException>()); Assert.IsTrue(cancel.IsCancellationRequested); Assert.Greater(updateCalled, 0); Assert.IsFalse(operation.HasValue); }
public async Task WaitForCompletionAsync() { int updateCalled = 0; var testResult = 100; var testResponse = new MockResponse(200); var operation = new TestOperation <int>("operation-id", TimeSpan.FromMilliseconds(10), testResult, testResponse) { UpdateCalled = () => { updateCalled++; } }; Response <int> operationResult = await operation.WaitForCompletionAsync(); Assert.Greater(updateCalled, 0); Assert.IsTrue(operation.HasCompleted); Assert.IsTrue(operation.HasValue); Assert.AreEqual(testResult, operationResult.Value); Assert.AreEqual(testResponse, operationResult.GetRawResponse()); Assert.AreEqual(testResult, operation.Value); Assert.AreEqual(testResponse, operation.GetRawResponse()); }