public async Task IfBodyIsNull_ThenForEachAsyncThrowsArgumentNullException_SyncDelegateOverload() { IPagedEnumerable <string> seq = new PagedAlphabet(); var ex = await Assert.ThrowsAsync <ArgumentNullException>(() => seq.ForEachAsync((Action <string>)null)); Assert.Equal("body", ex.ParamName); }
public async Task ForEachAsyncFuncSupportsCancellation() { PagedAlphabet seq = new PagedAlphabet(4, 10); //Call with an already cancelled cancellation token using CancellationTokenSource source = new CancellationTokenSource(); source.Cancel(); await Assert.ThrowsAsync <OperationCanceledException>(async() => await seq.ForEachAsync(item => Task.Delay(0), source.Token)); }
public async Task ForEachAsyncVisitsEveryMemberOfTheSequence_SyncDelegateOverload() { var visited = new List <string>(); var seq = new PagedAlphabet(); await seq.ForEachAsync(s => visited.Add(s)); Assert.Equal(26, visited.Count); Assert.Equal("A", visited.First()); Assert.Equal("Z", visited.Last()); }
public async Task ForEachAsyncVisitsEveryMemberOfTheSequence() { var visited = new List <string>(); var seq = new PagedAlphabet(); await seq.ForEachAsync(s => { visited.Add(s); return(Task.Delay(0)); }); Assert.Equal(26, visited.Count); Assert.Equal("A", visited.First()); Assert.Equal("Z", visited.Last()); }