< Summary

Class:Microsoft.Azure.Batch.AsyncListPoolUsageMetricsEnumerator
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\AsyncListPoolUsageMetrics.cs
Covered lines:21
Uncovered lines:10
Coverable lines:31
Total lines:91
Line coverage:67.7% (21 of 31)
Covered branches:2
Total branches:8
Branch coverage:25% (2 of 8)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
get_Current()-0%100%
GetNextBatchFromServerAsync()-60%25%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\AsyncListPoolUsageMetrics.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for license information.
 3
 4namespace Microsoft.Azure.Batch
 5{
 6    using System;
 7    using System.Diagnostics;
 8    using System.Linq;
 9    using System.Threading;
 10    using Models = Microsoft.Azure.Batch.Protocol.Models;
 11
 12    internal class AsyncListPoolUsageMetricsEnumerator : PagedEnumeratorBase<PoolUsageMetrics>
 13    {
 14        private readonly PoolOperations _parentPoolOperations;
 15        private readonly BehaviorManager _behaviorMgr;
 16        private readonly DateTime? _startTime;
 17        private readonly DateTime? _endTime;
 18        private readonly DetailLevel _detailLevel;
 19
 20#region // constructors
 21
 122        internal AsyncListPoolUsageMetricsEnumerator(
 123                PoolOperations parentPoolOperations,
 124                DateTime? startTime,
 125                DateTime? endTime,
 126                BehaviorManager behaviorMgr,
 127                DetailLevel detailLevel)
 28        {
 129            _parentPoolOperations = parentPoolOperations;
 130            _behaviorMgr = behaviorMgr;
 131            _startTime = startTime;
 132            _endTime = endTime;
 133            _detailLevel = detailLevel;
 134        }
 35
 36#endregion // constructors
 37
 38        public override PoolUsageMetrics Current  // for IPagedEnumerator<T> and IEnumerator<T>
 39        {
 40            get
 41            {
 42                // start with the current object off of base
 043                object curObj = base._currentBatch[base._currentIndex];
 44
 45                // it must be a protocol object from previous call
 046                Models.PoolUsageMetrics protocolObj = curObj as Models.PoolUsageMetrics;
 47
 48                Debug.Assert(null != protocolObj);
 49
 50                // wrap protocol object
 051                PoolUsageMetrics wrapped = new PoolUsageMetrics(protocolObj);
 52
 053                return wrapped;
 54            }
 55        }
 56
 57        /// <summary>
 58        /// fetch another batch of objects from the server
 59        /// </summary>
 60        protected async override System.Threading.Tasks.Task GetNextBatchFromServerAsync(SkipTokenHandler skipHandler, C
 61        {
 62            do
 63            {
 64                // start the protocol layer call
 165                var asyncTask =
 166                    _parentPoolOperations.ParentBatchClient.ProtocolLayer.ListPoolUsageMetrics(
 167                        _startTime,
 168                        _endTime,
 169                        skipHandler.SkipToken,
 170                        _behaviorMgr,
 171                        _detailLevel,
 172                        cancellationToken);
 73
 174                var response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
 75
 76                // remember any skiptoken returned.  This also sets the bool
 077                skipHandler.SkipToken = response.Body.NextPageLink;
 78
 79                // remember the protocol tasks returned
 080                base._currentBatch = null;
 81
 082                if (null != response.Body.GetEnumerator())
 83                {
 084                    base._currentBatch = response.Body.ToArray();
 85                }
 86            }
 87            // it is possible for there to be no results so we keep trying
 088            while (skipHandler.ThereIsMoreData && ((null == _currentBatch) || _currentBatch.Length <= 0));
 089        }
 90    }
 91}