AsyncEx.Tests.AsyncParallelTests.SerialAsyncExceptionTest C# (CSharp) Method

SerialAsyncExceptionTest() private method

private SerialAsyncExceptionTest ( ) : Task
return Task
        public async Task SerialAsyncExceptionTest()
        {
            var source = new[] { true, false };

            int ran = 0;

            var exception = new Exception();
            try
            {
                await AsyncParallel.ForEach(
                    source, new ParallelOptions { MaxDegreeOfParallelism = 1 },
                    async b =>
                    {
                        await Task.Yield();
                        if (b)
                            throw exception;

                        Interlocked.Increment(ref ran);
                    });
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual(exception, e);
            }
            finally
            {
                Assert.AreEqual(0, ran);
            }
        }