public async Task UpdateStatusAsync() { 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++; } }; while (!operation.HasValue) { Response updateResponse = await operation.UpdateStatusAsync(); await Task.Delay(1); } Assert.Greater(updateCalled, 0); Assert.IsTrue(operation.HasCompleted); Assert.IsTrue(operation.HasValue); Assert.AreEqual(testResult, operation.Value); Assert.AreEqual(testResponse, operation.GetRawResponse()); }
public void UpdateStatus() { int updateCalled = 0; var testResult = 10; var testResponse = new MockResponse(200); var operation = new TestOperation <int>(TimeSpan.FromMilliseconds(10), testResult, testResponse); operation.UpdateCalled = () => { updateCalled++; }; while (!operation.HasValue) { Response updateResponse = operation.UpdateStatus(); Thread.Sleep(1); } Assert.Greater(updateCalled, 0); Assert.IsTrue(operation.HasCompleted); Assert.IsTrue(operation.HasValue); Assert.AreEqual(testResult, operation.Value); Assert.AreEqual(testResponse, operation.GetRawResponse()); }
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()); }