public void ExpectCompletingTheOpInProcessResultToSkipRemainingTasks() { var task1 = new TestTask <int>(1); var task2 = new TestTask <int>(2); var task3 = new TestTask <int>(3); var operation = new AsyncOperation(); operation.Add(task1); operation.Add(task2, (result, op) => { var finalResult = new Result <string>("done"); op.Complete(finalResult); }); operation.Add(task3); Result <string> overallResult = null; operation.Execute(result => { overallResult = (Result <string>)result; }); Assert.IsTrue(task1.IsExecuted); Assert.IsTrue(task2.IsExecuted); Assert.IsFalse(task3.IsExecuted); Assert.IsFalse(overallResult.IsError); Assert.AreEqual("done", overallResult.Data); }
public void ExpectAddedTasksToBeExecutedInOrder() { var results = new List <int>(); var task1 = new TestTask <int>(1); var task2 = new TestTask <int>(2); var task3 = new TestTask <int>(3); Action <Result <int>, IOperationControls> processResult = (result, op) => { results.Add(result.Data); }; var operation = new AsyncOperation(); operation.Add(task1, processResult); operation.Add(task2, processResult); operation.Add(task3, processResult); operation.Execute(); Assert.AreEqual(1, results[0]); Assert.AreEqual(2, results[1]); Assert.AreEqual(3, results[2]); }
public void ExpectFailingTaskToFailTheOperation() { var task1 = new TestTask <int>(1); var task2 = new TestTask <int>(2) { Fails = true }; var task3 = new TestTask <int>(3); var operation = new AsyncOperation(); operation.Add(task1); operation.Add(task2); operation.Add(task3); OperationResult overallResult = null; operation.Execute(result => { overallResult = result; }); Assert.IsTrue(task1.IsExecuted); Assert.IsTrue(task2.IsExecuted); Assert.IsFalse(task3.IsExecuted); Assert.IsTrue(overallResult.IsError); }
private static void SyncProjectInternal(PackageListStatus packageListStatus, Action <OperationResult> onComplete) { if (packageListStatus.IsProjectUpToDate) { onComplete(new OperationResult()); return; } var operation = new AsyncOperation(); foreach (var packageStatus in packageListStatus.Packages) { var version = packageStatus.RequiredVersion; var packageName = packageStatus.PackageName; var gitUrl = packageStatus.GitUrl; var relativeInstallDirectory = Settings.RelativePackagesDirectoryPath + packageName; var absoluteInstallDirectory = Settings.AbsolutePackagesDirectoryPath + packageName; if (packageStatus.IsMissing) { operation.Add(new AddSubmoduleTask(gitUrl, relativeInstallDirectory)); operation.Add(new CheckoutSubmoduleTask(absoluteInstallDirectory, version)); } else if (packageStatus.IsOnWrongVersion) { operation.Add(new CheckoutSubmoduleTask(absoluteInstallDirectory, version)); } } operation.Execute(onComplete); }
public void ExpectAddToThrowIfTheOperationIsRunning() { Assert.Throws <InvalidOperationException>(() => { var operation = new AsyncOperation(); operation.Add(new TestTask <int>(1), (result, op) => { operation.Add(new TestTask <int>(2), (result1, op1) => {}); }); operation.Execute(); }); }
public void ExpectAddedTaskToBeExecutedAndDataToBePassedToProcessResultCallback() { var isProcessResultExecuted = false; var resultValue = 0; var task = new TestTask <int>(42); var operation = new AsyncOperation(); operation.Add(task, (r, op) => { resultValue = r.Data; isProcessResultExecuted = true; }); operation.Execute(); Assert.IsTrue(task.IsExecuted); Assert.IsTrue(isProcessResultExecuted); Assert.AreEqual(42, resultValue); }
public void ExpectFailingOpInProcessResultToFailTheOperation() { var task1 = new TestTask <int>(1); var task2 = new TestTask <int>(2); var task3 = new TestTask <int>(3); var operation = new AsyncOperation(); operation.Add(task1); operation.Add(task2, (result, op) => { op.Fail(new Error("test-error", "Error")); }); operation.Add(task3); OperationResult overallResult = null; operation.Execute(result => { overallResult = result; }); Assert.IsTrue(task1.IsExecuted); Assert.IsTrue(task2.IsExecuted); Assert.IsFalse(task3.IsExecuted); Assert.IsTrue(overallResult.IsError); }