public void Cancellation() { var cancel = new CancellationTokenSource(); cancel.CancelAfter(100); int updateCalled = 0; var operation = new TestOperation <int>(TimeSpan.FromMilliseconds(1000), 100, null); operation.PollingInterval = TimeSpan.FromMilliseconds(10); operation.UpdateCalled = () => { updateCalled++; }; Assert.That(async() => { _ = await operation.WaitCompletionAsync(cancel.Token); }, Throws.InstanceOf <OperationCanceledException>()); Assert.IsTrue(cancel.IsCancellationRequested); Assert.Greater(updateCalled, 0); Assert.IsFalse(operation.HasValue); }
public async Task WaitCompletionAsync() { int updateCalled = 0; var testResult = 100; var testResponse = new MockResponse(200); var operation = new TestOperation <int>(TimeSpan.FromMilliseconds(10), testResult, testResponse); operation.PollingInterval = TimeSpan.FromMilliseconds(1); operation.UpdateCalled = () => { updateCalled++; }; Response <int> operationResult = await operation.WaitCompletionAsync(); 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()); }