public async Task TestFailedOperation()
        {
            object operationPlaceholder  = new object();
            bool   getErrorDataCalled    = false;
            bool   getErrorMessageCalled = false;

            try
            {
                await OperationUtils.AwaitOperationAsync(
                    operationPlaceholder,
                    refreshOperation : x => Task.FromResult(x),
                    isFinished : _ => true,
                    getErrorData : x => { getErrorDataCalled = true; return(x); },
                    getErrorMessage : x => { getErrorMessageCalled = true; return("Error message"); });

                // Should not reach here, an exception should be thrown.
                Assert.Fail();
            }
            catch (DataSourceException)
            {
                // We should throw DataSourceException, and the method to get the error data
                // should have been called.
                Assert.IsTrue(getErrorDataCalled && getErrorMessageCalled);
            }
        }
        public async Task TestCancelledOperation()
        {
            bool exceptionThrown = false;

            try
            {
                object operationPlaceholder    = new object();
                CancellationTokenSource source = new CancellationTokenSource();

                Task operationTask = OperationUtils.AwaitOperationAsync <object, object>(
                    operationPlaceholder,
                    refreshOperation: x => Task.FromResult(x),
                    isFinished: x => false,
                    getErrorData: x => null,
                    getErrorMessage: x => null,
                    token: source.Token);

                source.Cancel();
                await operationTask;
            }
            catch (Exception ex) when(ex is OperationCanceledException || ex is TaskCanceledException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }
        public async Task TestCompletedOperation()
        {
            int    count = 0;
            object operationPlaceholder = new object();

            await OperationUtils.AwaitOperationAsync <object, object>(
                operationPlaceholder,
                refreshOperation : x => { count++; return(Task.FromResult(x)); },
                isFinished : x => count >= 5,
                getErrorData : x => null,
                getErrorMessage : x => null,
                delay : TimeSpan.Zero);
        }