< Summary

Class:Azure.Core.PageResponseEnumerator
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\PageResponseEnumerator.cs
Covered lines:18
Uncovered lines:2
Coverable lines:20
Total lines:74
Line coverage:90% (18 of 20)
Covered branches:11
Total branches:14
Branch coverage:78.5% (11 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
CreateEnumerable(...)-100%100%
CreateEnumerable(...)-0%100%
CreateAsyncEnumerable(...)-100%100%
CreateAsyncEnumerable(...)-0%100%
.ctor(...)-100%100%
AsPages()-100%75%
.ctor(...)-100%100%
AsPages()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\PageResponseEnumerator.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4#nullable enable
 5
 6using System;
 7using System.Collections.Generic;
 8using System.Threading.Tasks;
 9
 10namespace Azure.Core
 11{
 12    internal static class PageResponseEnumerator
 13    {
 14        public static FuncPageable<T> CreateEnumerable<T>(Func<string?, Page<T>> pageFunc) where T : notnull
 15        {
 216            return new FuncPageable<T>((continuationToken, pageSizeHint) => pageFunc(continuationToken));
 17        }
 18
 19        public static FuncPageable<T> CreateEnumerable<T>(Func<string?, int?, Page<T>> pageFunc) where T : notnull
 20        {
 021            return new FuncPageable<T>(pageFunc);
 22        }
 23
 24        public static AsyncPageable<T> CreateAsyncEnumerable<T>(Func<string?, Task<Page<T>>> pageFunc) where T : notnull
 25        {
 426            return new FuncAsyncPageable<T>((continuationToken, pageSizeHint) => pageFunc(continuationToken));
 27        }
 28
 29        public static AsyncPageable<T> CreateAsyncEnumerable<T>(Func<string?, int?, Task<Page<T>>> pageFunc) where T : n
 30        {
 031            return new FuncAsyncPageable<T>(pageFunc);
 32        }
 33
 34        internal class FuncAsyncPageable<T> : AsyncPageable<T> where T : notnull
 35        {
 36            private readonly Func<string?, int?, Task<Page<T>>> _pageFunc;
 37
 238            public FuncAsyncPageable(Func<string?, int?, Task<Page<T>>> pageFunc)
 39            {
 240                _pageFunc = pageFunc;
 241            }
 42
 43            public override async IAsyncEnumerable<Page<T>> AsPages(string? continuationToken = default, int? pageSizeHi
 44            {
 45                do
 46                {
 247                    Page<T> pageResponse = await _pageFunc(continuationToken, pageSizeHint).ConfigureAwait(false);
 148                    yield return pageResponse;
 149                    continuationToken = pageResponse.ContinuationToken;
 250                } while (continuationToken != null);
 151            }
 52        }
 53
 54        internal class FuncPageable<T> : Pageable<T> where T : notnull
 55        {
 56            private readonly Func<string?, int?, Page<T>> _pageFunc;
 57
 158            public FuncPageable(Func<string?, int?, Page<T>> pageFunc)
 59            {
 160                _pageFunc = pageFunc;
 161            }
 62
 63            public override IEnumerable<Page<T>> AsPages(string? continuationToken = default, int? pageSizeHint = defaul
 64            {
 65                do
 66                {
 167                    Page<T> pageResponse = _pageFunc(continuationToken, pageSizeHint);
 168                    yield return pageResponse;
 169                    continuationToken = pageResponse.ContinuationToken;
 270                } while (continuationToken != null);
 171            }
 72        }
 73    }
 74}