public void ForEachAsync_throws_on_null_arguments() { var progressReporter = new ProgressReporter <int>(processingStatus => { }); var items = Enumerable.Range(1, 4).ToList(); Func <Task> action = () => progressReporter.ForEachAsync(null, item => Task.FromResult(true)); action.ShouldThrow <ArgumentNullException>(); action = () => progressReporter.ForEachAsync(items, null); action.ShouldThrow <ArgumentNullException>(); }
public async Task ForEachAsync_reports_status_with_expected_ItemCount() { var items = Enumerable.Range(1, 5).ToList(); var progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.ItemCount.Should().Be(items.Count); }); await progressReporter.ForEachAsync(items, item => Task.FromResult(true)); }
public async Task ForEachAsync_reports_status_with_each_iteration() { var sum = 0; var progressReporter = new ProgressReporter <int>(processingStatus => { sum += processingStatus.SourceItem; }); var items = Enumerable.Range(1, 5).ToList(); await progressReporter.ForEachAsync(items, item => Task.FromResult(true)); sum.Should().Be(15); }
public async Task ForEachAsync_continues_after_an_exception() { var last = 0; var items = Enumerable.Range(1, 5).ToList(); var progressReporter = new ProgressReporter <int>(processingStatus => { last = processingStatus.SourceItem; }); await progressReporter.ForEachAsync( items, item => { throw new Exception("Test"); }); last.Should().Be(5); }
public async Task ForEachAsync_reports_status_with_expected_Exception() { var items = Enumerable.Range(1, 1).ToList(); var progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.Exception.Should().BeNull(); }); await progressReporter.ForEachAsync(items, item => Task.FromResult(true)); var expectedException = new Exception("Test"); progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.Exception.Should().BeSameAs(expectedException); }); await progressReporter.ForEachAsync(items, item => { throw expectedException; }); }
public async Task ForEachAsync_reports_status_with_expected_PercentageComplete() { var items = Enumerable.Range(1, 5).ToList(); var progressReporter = new ProgressReporter <int>( processingStatus => { processingStatus.PercentageComplete.Should() .Be(Convert.ToDouble(processingStatus.ItemsProcessed) / processingStatus.ItemCount); }); await progressReporter.ForEachAsync(items, item => Task.FromResult(true)); }
public async Task ForEachAsync_iterates_each_item() { var sum = 0; var progressReporter = new ProgressReporter <int>(processingStatus => { }); var items = Enumerable.Range(1, 5).ToList(); await progressReporter.ForEachAsync( items, item => { sum += item; return(Task.FromResult(true)); }); sum.Should().Be(15); }