< Summary

Class:Azure.Core.OperationHelpers
Assembly:Azure.ResourceManager.Network
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\OperationHelpers.cs
Covered lines:0
Uncovered lines:14
Coverable lines:14
Total lines:57
Line coverage:0% (0 of 14)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_DefaultPollingInterval()-0%100%
GetValue(...)-0%0%
GetValue(...)-0%0%
DefaultWaitForCompletionAsync(...)-0%100%
DefaultWaitForCompletionAsync()-0%0%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Threading;
 6using System.Threading.Tasks;
 7
 8#nullable enable
 9
 10namespace Azure.Core
 11{
 12    internal static class OperationHelpers
 13    {
 014        public static TimeSpan DefaultPollingInterval { get; } = TimeSpan.FromSeconds(1);
 15
 16        public static T GetValue<T>(ref T? value) where T: class
 17        {
 018            if (value is null)
 19            {
 020                throw new InvalidOperationException("The operation has not completed yet.");
 21            }
 22
 023            return value;
 24        }
 25
 26        public static T GetValue<T>(ref T? value) where T: struct
 27        {
 028            if (value == null)
 29            {
 030                throw new InvalidOperationException("The operation has not completed yet.");
 31            }
 32
 033            return value.Value;
 34        }
 35
 36        public static ValueTask<Response<TResult>> DefaultWaitForCompletionAsync<TResult>(this Operation<TResult> operat
 37            where TResult : notnull
 38        {
 039            return operation.WaitForCompletionAsync(DefaultPollingInterval, cancellationToken);
 40        }
 41
 42        public static async ValueTask<Response<TResult>> DefaultWaitForCompletionAsync<TResult>(this Operation<TResult> 
 43            where TResult : notnull
 44        {
 045            while (true)
 46            {
 047                await operation.UpdateStatusAsync(cancellationToken).ConfigureAwait(false);
 048                if (operation.HasCompleted)
 49                {
 050                    return Response.FromValue(operation.Value, operation.GetRawResponse());
 51                }
 52
 053                await Task.Delay(pollingInterval, cancellationToken).ConfigureAwait(false);
 54            }
 055        }
 56    }
 57}