public void ForEach_throws_on_null_arguments() { var progressReporter = new ProgressReporter <int>(processingStatus => { }); var items = Enumerable.Range(1, 4).ToList(); Action action = () => progressReporter.ForEach(null, item => true); action.ShouldThrow <ArgumentNullException>(); action = () => progressReporter.ForEach(items, null); action.ShouldThrow <ArgumentNullException>(); }
public void ForEach_reports_status_with_expected_ItemCount() { var items = Enumerable.Range(1, 4).ToList(); var progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.ItemCount.Should().Be(items.Count); }); progressReporter.ForEach(items, item => true); }
public void ForEach_reports_status_with_expected_source_item() { var last = 0; var progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.ItemsProcessed.Should().Be(++last); }); var items = Enumerable.Range(1, 4).ToList(); progressReporter.ForEach(items, item => true); }
public void ForEach_reports_status_with_each_iteration() { var sum = 0; var progressReporter = new ProgressReporter <int>(processingStatus => { sum += processingStatus.SourceItem; }); var items = Enumerable.Range(1, 4).ToList(); progressReporter.ForEach(items, item => true); sum.Should().Be(10); }
public void ForEach_reports_status_with_expected_Success() { var items = Enumerable.Range(1, 1).ToList(); var progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.Success.Should().Be(true); }); progressReporter.ForEach(items, item => true); progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.Success.Should().Be(false); }); progressReporter.ForEach(items, item => false); }
public void ForEach_continues_after_an_exception() { var last = 0; var items = Enumerable.Range(1, 4).ToList(); var progressReporter = new ProgressReporter <int>(processingStatus => { last = processingStatus.SourceItem; }); progressReporter.ForEach( items, item => { throw new Exception("Test"); }); last.Should().Be(4); }
public void ForEach_reports_status_with_expected_Exception() { var items = Enumerable.Range(1, 1).ToList(); var progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.Exception.Should().BeNull(); }); progressReporter.ForEach(items, item => true); var expectedException = new Exception("Test"); progressReporter = new ProgressReporter <int>(processingStatus => { processingStatus.Exception.Should().BeSameAs(expectedException); }); progressReporter.ForEach(items, item => { throw expectedException; }); }
public void ForEach_reports_status_with_expected_PercentageComplete() { var items = Enumerable.Range(1, 4).ToList(); var progressReporter = new ProgressReporter <int>( processingStatus => { processingStatus.PercentageComplete.Should() .Be(Convert.ToDouble(processingStatus.ItemsProcessed) / processingStatus.ItemCount); }); progressReporter.ForEach(items, item => true); }
public void ForEach_iterates_each_item() { var sum = 0; var progressReporter = new ProgressReporter <int>(processingStatus => { }); var items = Enumerable.Range(1, 4).ToList(); progressReporter.ForEach( items, item => { sum += item; return(true); }); sum.Should().Be(10); }