コード例 #1
0
        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>();
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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; });
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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);
        }