< Summary

Class:Azure.Security.KeyVault.KeyVaultPage`1
Assembly:Azure.Security.KeyVault.Secrets
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Shared\src\KeyVaultPage.cs
Covered lines:19
Uncovered lines:0
Coverable lines:19
Total lines:70
Line coverage:100% (19 of 19)
Covered branches:12
Total branches:12
Branch coverage:100% (12 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
get_Items()-100%100%
get_NextLink()-100%100%
Azure.Security.KeyVault.IJsonDeserializable.ReadProperties(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Shared\src\KeyVaultPage.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text.Json;
 6
 7namespace Azure.Security.KeyVault
 8{
 9    /// <summary>
 10    /// Defines a page in Azure responses.
 11    /// </summary>
 12    /// <typeparam name="T">Type of the page content items</typeparam>
 13    internal class KeyVaultPage<T> : IJsonDeserializable
 14        where T : IJsonDeserializable
 15    {
 16        private T[] _items;
 17        private readonly Func<T> _itemFactory;
 18
 4419        internal KeyVaultPage(Func<T> itemFactory)
 20        {
 4421            _itemFactory = itemFactory;
 4422        }
 23
 24        /// <summary>
 25        /// Gets the content items.
 26        /// </summary>
 4427        public ReadOnlySpan<T> Items { get => _items.AsSpan(); }
 28
 29        /// <summary>
 30        /// Gets the link to the next page.
 31        /// </summary>
 7232        public Uri NextLink { get; private set; }
 33
 34        void IJsonDeserializable.ReadProperties(JsonElement json)
 35        {
 26436            foreach (JsonProperty prop in json.EnumerateObject())
 37            {
 8838                switch (prop.Name)
 39                {
 40                    case "value":
 4441                        JsonElement value = prop.Value;
 4442                        if (value.ValueKind != JsonValueKind.Null)
 43                        {
 4444                            _items = new T[value.GetArrayLength()];
 45
 4446                            int i = 0;
 47
 132048                            foreach (JsonElement elem in value.EnumerateArray())
 49                            {
 61650                                _items[i] = _itemFactory();
 51
 61652                                _items[i].ReadProperties(elem);
 53
 61654                                i++;
 55                            }
 56                        }
 57                        break;
 58
 59                    case "nextLink":
 4460                        var nextLinkUrl = prop.Value.GetString();
 4461                        if (!string.IsNullOrEmpty(nextLinkUrl))
 62                        {
 2863                            NextLink = new Uri(nextLinkUrl);
 64                        }
 65                        break;
 66                }
 67            }
 4468        }
 69    }
 70}