Beispiel #1
0
        public async Task ForEachAsync_WhenFuncIsNull_Throws()
        {
            var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                () => NuGetAsyncExtensions.ForEachAsync(Enumerable.Empty <string>(), maxDegreeOfParallelism: 2, func: null));

            Assert.Equal("func", exception.ParamName);
        }
Beispiel #2
0
        public async Task ForEachAsync_WhenMaxDegreeOfParallelismIsLessThanOne_Throws(int maxDegreeOfParallelism)
        {
            var exception = await Assert.ThrowsAsync <ArgumentOutOfRangeException>(
                () => NuGetAsyncExtensions.ForEachAsync(Enumerable.Empty <string>(), maxDegreeOfParallelism, func: _ => Task.FromResult(0)));

            Assert.Equal("maxDegreeOfParallelism", exception.ParamName);
            Assert.StartsWith($"The argument must be within the range from 1 (inclusive) to {int.MaxValue} (inclusive).", exception.Message);
        }
Beispiel #3
0
        public async Task ForEachAsync_WhenEnumerableIsNull_Throws()
        {
            IEnumerable <string> enumerable = null;

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                () => NuGetAsyncExtensions.ForEachAsync(enumerable, maxDegreeOfParallelism: 2, func: _ => Task.FromResult(0)));

            Assert.Equal("enumerable", exception.ParamName);
        }
Beispiel #4
0
        public async Task ForEachAsync_WithValidArguments_ProcessesAllItems()
        {
            var enumerable = Enumerable.Range(1, 100);
            var bag        = new ConcurrentBag <int>();

            await NuGetAsyncExtensions.ForEachAsync(
                enumerable,
                maxDegreeOfParallelism : 10,
                func : i =>
            {
                bag.Add(i);

                return(Task.FromResult(0));
            });

            var actualResults = bag.ToArray();

            Array.Sort(actualResults);

            Assert.Equal(enumerable, actualResults);
        }