public async void Time_Moves_Forward() { var ttr = new TestTaskRunner(1000); var t1 = ttr.CreateLambdaTask <long>(tcs => tcs.SetResult(ttr.Now), 0, true); var t2 = ttr.CreateLambdaTask <long>(tcs => tcs.SetResult(ttr.Now), 500, true); var t3 = ttr.CreateLambdaTask <long>(tcs => tcs.SetResult(ttr.Now), 1000, true); var t4 = ttr.CreateLambdaTask <long>(tcs => tcs.SetResult(ttr.Now), 1500, true); ttr.AdvanceTimeBy(500); Assert.Equal(1000, await t1); Assert.Equal(1000, await t2); Assert.Equal(1000, await t3); Assert.Equal(1500, await t4); }
public void Callback_Absolute() { var ttr = new TestTaskRunner(50); var count = 0; var t1 = ttr.CreateActionTask(() => count++, 50, true); var t2 = ttr.CreateActionTask(() => throw new InvalidOperationException(), 100, true); var t3 = ttr.CreateLambdaTask <long>(tcs => tcs.SetResult(ttr.Now), 150, true); var t4 = ttr.CreateLambdaTask <long>(tcs => throw new InvalidOperationException(), 150, true); Assert.Equal(0, count); // T = 50 ---------------------------------------------- ttr.AdvanceTimeBy(0); Assert.True(t1.IsCompleted); Assert.Equal(1, count); // T = 100 ---------------------------------------------- ttr.AdvanceTimeBy(50); Assert.True(t2.IsFaulted); Assert.True(t2.Exception.InnerException is InvalidOperationException); Assert.False(t3.IsCompleted); Assert.False(t4.IsCompleted); // T = 150 ---------------------------------------------- ttr.AdvanceTimeBy(50); Assert.True(t3.IsCompleted); Assert.Equal(150L, t3.Result); Assert.True(t4.IsFaulted); Assert.True(t4.Exception.InnerException is InvalidOperationException); }