< Summary

Class:Azure.Core.PageResponseEnumerator
Assembly:Azure.Security.KeyVault.Keys
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        {
 2016            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        {
 2026            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
 1038            public FuncAsyncPageable(Func<string?, int?, Task<Page<T>>> pageFunc)
 39            {
 1040                _pageFunc = pageFunc;
 1041            }
 42
 43            public override async IAsyncEnumerable<Page<T>> AsPages(string? continuationToken = default, int? pageSizeHi
 44            {
 45                do
 46                {
 1047                    Page<T> pageResponse = await _pageFunc(continuationToken, pageSizeHint).ConfigureAwait(false);
 1048                    yield return pageResponse;
 1049                    continuationToken = pageResponse.ContinuationToken;
 2050                } while (continuationToken != null);
 1051            }
 52        }
 53
 54        internal class FuncPageable<T> : Pageable<T> where T : notnull
 55        {
 56            private readonly Func<string?, int?, Page<T>> _pageFunc;
 57
 1058            public FuncPageable(Func<string?, int?, Page<T>> pageFunc)
 59            {
 1060                _pageFunc = pageFunc;
 1061            }
 62
 63            public override IEnumerable<Page<T>> AsPages(string? continuationToken = default, int? pageSizeHint = defaul
 64            {
 65                do
 66                {
 1067                    Page<T> pageResponse = _pageFunc(continuationToken, pageSizeHint);
 1068                    yield return pageResponse;
 1069                    continuationToken = pageResponse.ContinuationToken;
 2070                } while (continuationToken != null);
 1071            }
 72        }
 73    }
 74}