public void Defer_NoFunc_DoesNotAddToTaskList() { Deferment deferment = new Deferment(); deferment.Defer((Func <Task>)null, 5000, CancellationToken.None); deferment.Tasks.Should().BeEmpty(); }
public void Defer_AddsToTaskList() { Deferment deferment = new Deferment(); deferment.Defer(() => { }, 5000, CancellationToken.None); deferment.Tasks.Should().NotBeEmpty(); }
public async Task Defer_RunsFunc() { bool invokedFunc = false; Deferment deferment = new Deferment(); deferment.Defer(async() => { await Task.Delay(0); invokedFunc = true; }, 0); await Task.WhenAll(deferment.Tasks.ToArray()); invokedFunc.Should().BeTrue(); }
public async Task Defer_RunsAction() { bool invokedAction = false; Deferment deferment = new Deferment(); deferment.Defer(() => { invokedAction = true; }, 0, CancellationToken.None); await Task.WhenAll(deferment.Tasks.ToArray()); invokedAction.Should().BeTrue(); }
public async Task Defer_RemovesFromTasklistWhenComplete() { Deferment deferment = new Deferment(); deferment.Defer(() => { }, 10, CancellationToken.None); deferment.Tasks.Should().NotBeEmpty(); await Task.WhenAll(deferment.Tasks.ToArray()); deferment.Tasks.Should().BeEmpty(); }
public async Task Defers_WaitsBeforeInvokingAction() { int delay = 10; Stopwatch sw = Stopwatch.StartNew(); Deferment deferment = new Deferment(); deferment.Defer(() => { sw.Stop(); }, delay, CancellationToken.None); await Task.WhenAll(deferment.Tasks.ToArray()); sw.ElapsedMilliseconds.Should().BeGreaterOrEqualTo(delay); }
public async Task Defer_CancellationDuringDelay_DoesNotInvokeAction() { bool invokedAction = false; Deferment deferment = new Deferment(); CancellationTokenSource cts = new CancellationTokenSource(5); deferment.Defer(() => { invokedAction = true; }, 10, cts.Token); await Task.WhenAll(deferment.Tasks.ToArray()); invokedAction.Should().BeFalse(); }
public void Defer_Cancellation_DoesNotThrow() { Deferment deferment = new Deferment(); CancellationTokenSource cts = new CancellationTokenSource(1); try { deferment.Defer(() => { }, 10, cts.Token); } catch (Exception ex) { Assert.Fail($"{ex.GetType()} should not have been thrown"); } }