< Summary

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

Metrics

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

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
 2019        internal KeyVaultPage(Func<T> itemFactory)
 20        {
 2021            _itemFactory = itemFactory;
 2022        }
 23
 24        /// <summary>
 25        /// Gets the content items.
 26        /// </summary>
 2027        public ReadOnlySpan<T> Items { get => _items.AsSpan(); }
 28
 29        /// <summary>
 30        /// Gets the link to the next page.
 31        /// </summary>
 032        public Uri NextLink { get; private set; }
 33
 34        void IJsonDeserializable.ReadProperties(JsonElement json)
 35        {
 11236            foreach (JsonProperty prop in json.EnumerateObject())
 37            {
 3638                switch (prop.Name)
 39                {
 40                    case "value":
 2041                        JsonElement value = prop.Value;
 2042                        if (value.ValueKind != JsonValueKind.Null)
 43                        {
 2044                            _items = new T[value.GetArrayLength()];
 45
 2046                            int i = 0;
 47
 15248                            foreach (JsonElement elem in value.EnumerateArray())
 49                            {
 5650                                _items[i] = _itemFactory();
 51
 5652                                _items[i].ReadProperties(elem);
 53
 5654                                i++;
 55                            }
 56                        }
 57                        break;
 58
 59                    case "nextLink":
 1660                        var nextLinkUrl = prop.Value.GetString();
 1661                        if (!string.IsNullOrEmpty(nextLinkUrl))
 62                        {
 063                            NextLink = new Uri(nextLinkUrl);
 64                        }
 65                        break;
 66                }
 67            }
 2068        }
 69    }
 70}