< Summary

Class:Azure.Core.PageResponseEnumerator
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\PageResponseEnumerator.cs
Covered lines:9
Uncovered lines:11
Coverable lines:20
Total lines:74
Line coverage:45% (9 of 20)
Covered branches:9
Total branches:14
Branch coverage:64.2% (9 of 14)

Metrics

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

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        {
 016            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        {
 4026            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
 2038            public FuncAsyncPageable(Func<string?, int?, Task<Page<T>>> pageFunc)
 39            {
 2040                _pageFunc = pageFunc;
 2041            }
 42
 43            public override async IAsyncEnumerable<Page<T>> AsPages(string? continuationToken = default, int? pageSizeHi
 44            {
 45                do
 46                {
 2047                    Page<T> pageResponse = await _pageFunc(continuationToken, pageSizeHint).ConfigureAwait(false);
 2048                    yield return pageResponse;
 2049                    continuationToken = pageResponse.ContinuationToken;
 4050                } while (continuationToken != null);
 2051            }
 52        }
 53
 54        internal class FuncPageable<T> : Pageable<T> where T : notnull
 55        {
 56            private readonly Func<string?, int?, Page<T>> _pageFunc;
 57
 058            public FuncPageable(Func<string?, int?, Page<T>> pageFunc)
 59            {
 060                _pageFunc = pageFunc;
 061            }
 62
 63            public override IEnumerable<Page<T>> AsPages(string? continuationToken = default, int? pageSizeHint = defaul
 64            {
 65                do
 66                {
 067                    Page<T> pageResponse = _pageFunc(continuationToken, pageSizeHint);
 068                    yield return pageResponse;
 069                    continuationToken = pageResponse.ContinuationToken;
 070                } while (continuationToken != null);
 071            }
 72        }
 73    }
 74}