コード例 #1
0
        public async Task IfBodyIsNull_ThenForEachAsyncThrowsArgumentNullException_SyncDelegateOverload()
        {
            IPagedEnumerable <string> seq = new PagedAlphabet();

            var ex = await Assert.ThrowsAsync <ArgumentNullException>(() => seq.ForEachAsync((Action <string>)null));

            Assert.Equal("body", ex.ParamName);
        }
コード例 #2
0
        public async Task ForEachAsyncFuncSupportsCancellation()
        {
            PagedAlphabet seq = new PagedAlphabet(4, 10);

            //Call with an already cancelled cancellation token
            using CancellationTokenSource source = new CancellationTokenSource();
            source.Cancel();

            await Assert.ThrowsAsync <OperationCanceledException>(async() => await seq.ForEachAsync(item => Task.Delay(0), source.Token));
        }
コード例 #3
0
        public async Task ForEachAsyncVisitsEveryMemberOfTheSequence_SyncDelegateOverload()
        {
            var visited = new List <string>();

            var seq = new PagedAlphabet();

            await seq.ForEachAsync(s => visited.Add(s));

            Assert.Equal(26, visited.Count);
            Assert.Equal("A", visited.First());
            Assert.Equal("Z", visited.Last());
        }
コード例 #4
0
        public async Task ForEachAsyncVisitsEveryMemberOfTheSequence()
        {
            var visited = new List <string>();

            var seq = new PagedAlphabet();

            await seq.ForEachAsync(s => { visited.Add(s); return(Task.Delay(0)); });

            Assert.Equal(26, visited.Count);
            Assert.Equal("A", visited.First());
            Assert.Equal("Z", visited.Last());
        }