public async Task StartAwaitSafelyAwaits() { var runOrder = new List <string>(); var task = new ActionTask(Token, _ => { throw new InvalidOperationException(); }) .Catch(_ => { }); await task.StartAwait(_ => { }); }
public async Task GetTopMostTaskInCreatedState() { var task1 = new ActionTask(Token, () => { }); await task1.StartAwait(); var task2 = new TestActionTask(Token, _ => { }); var task3 = new TestActionTask(Token, _ => { }); task1.Then(task2).Then(task3); var top = task3.Test_GetTopMostTaskInCreatedState(); Assert.AreSame(task2, top); }
public async Task GetFirstStartableTask_ReturnsNullWhenItsAlreadyStarted() { var task1 = new ActionTask(Token, () => { }); await task1.StartAwait(); var task2 = new TestActionTask(Token, _ => { }); var task3 = new TestActionTask(Token, _ => { }); task1.Then(task2).Then(task3); var top = task3.Test_GetFirstStartableTask(); Assert.AreSame(task2, top); }
public async Task TaskOnFailureGetsCalledWhenExceptionHappensUpTheChain() { var runOrder = new List <string>(); var exceptions = new List <Exception>(); var task = new ActionTask(Token, _ => { throw new InvalidOperationException(); }) .Then(_ => { runOrder.Add("1"); }) .Catch(ex => exceptions.Add(ex)) .Then(() => runOrder.Add("OnFailure"), runOptions: TaskRunOptions.OnFailure) .Finally((s, e) => { }, TaskAffinity.Concurrent); await task.StartAwait(_ => { }); CollectionAssert.AreEqual( new string[] { typeof(InvalidOperationException).Name }, exceptions.Select(x => x.GetType().Name).ToArray()); CollectionAssert.AreEqual( new string[] { "OnFailure" }, runOrder); }