public void ItemExceptionIsPropagated() { IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create ( Task.FromResult(42), Task.FromException <int>(new InvalidOperationException()) ); Func <Task <int[]> > faultyAct = () => enumerator.ToArray(); faultyAct.ShouldThrow <InvalidOperationException>(); }
public void ItemExceptionIsPropagated() { IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create ( Task.Delay(100).ContinueWith(_ => 64), Task.FromException <int>(new InvalidOperationException()) ); Func <Task> act = () => enumerator.ForEach(_ => { }); act.ShouldThrow <InvalidOperationException>(); }
public async Task ReturnsItemsInOrder() { Task <int>[] itemTasks = new Task <int>[] { Task.FromResult(42), Task.Delay(100).ContinueWith(_ => 64), Task.FromResult(128) }; IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create(itemTasks); int[] array = await enumerator.ToArray().ConfigureAwait(true); int[] expectedItems = await Task.WhenAll(itemTasks).ConfigureAwait(true); array.Should().HaveEquivalentItems(expectedItems); }
public async Task LambdaIsCalledForEachItem() { List <int> callArguments = new List <int>(); Task <int>[] itemTasks = new Task <int>[] { Task.FromResult(42), Task.Delay(100).ContinueWith(_ => 64), Task.FromResult(128) }; IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create(itemTasks); await enumerator.ForEach(item => callArguments.Add(item)).ConfigureAwait(true); int[] expectedItems = await Task.WhenAll(itemTasks).ConfigureAwait(true); callArguments.Should().HaveEquivalentItems(expectedItems); }
public void LambdaExceptionIsPropagated() { const int dangerousItem = 42; IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create ( Task.Delay(100).ContinueWith(_ => 64), Task.FromResult(dangerousItem) ); Func <Task> act = () => enumerator.ForEach ( value => { if (value == dangerousItem) { throw new InvalidOperationException(); } } ); act.ShouldThrow <InvalidOperationException>(); }