コード例 #1
0
        public void ItemExceptionIsPropagated()
        {
            IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create
                                                (
                Task.FromResult(42),
                Task.FromException <int>(new InvalidOperationException())
                                                );

            Func <Task <int[]> > faultyAct = () => enumerator.ToArray();

            faultyAct.ShouldThrow <InvalidOperationException>();
        }
コード例 #2
0
        public void ItemExceptionIsPropagated()
        {
            IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create
                                                (
                Task.Delay(100).ContinueWith(_ => 64),
                Task.FromException <int>(new InvalidOperationException())
                                                );

            Func <Task> act = () => enumerator.ForEach(_ => { });

            act.ShouldThrow <InvalidOperationException>();
        }
コード例 #3
0
        public async Task ReturnsItemsInOrder()
        {
            Task <int>[] itemTasks = new Task <int>[]
            {
                Task.FromResult(42),
                Task.Delay(100).ContinueWith(_ => 64),
                Task.FromResult(128)
            };

            IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create(itemTasks);

            int[] array = await enumerator.ToArray().ConfigureAwait(true);

            int[] expectedItems = await Task.WhenAll(itemTasks).ConfigureAwait(true);

            array.Should().HaveEquivalentItems(expectedItems);
        }
コード例 #4
0
        public async Task LambdaIsCalledForEachItem()
        {
            List <int> callArguments = new List <int>();

            Task <int>[] itemTasks = new Task <int>[]
            {
                Task.FromResult(42),
                Task.Delay(100).ContinueWith(_ => 64),
                Task.FromResult(128)
            };

            IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create(itemTasks);
            await enumerator.ForEach(item => callArguments.Add(item)).ConfigureAwait(true);

            int[] expectedItems = await Task.WhenAll(itemTasks).ConfigureAwait(true);

            callArguments.Should().HaveEquivalentItems(expectedItems);
        }
コード例 #5
0
        public void LambdaExceptionIsPropagated()
        {
            const int dangerousItem           = 42;
            IAsyncEnumerator <int> enumerator = TaskAsyncEnumerator.Create
                                                (
                Task.Delay(100).ContinueWith(_ => 64),
                Task.FromResult(dangerousItem)
                                                );

            Func <Task> act
                = () =>
                  enumerator.ForEach
                  (
                      value =>
            {
                if (value == dangerousItem)
                {
                    throw new InvalidOperationException();
                }
            }
                  );

            act.ShouldThrow <InvalidOperationException>();
        }