< Summary

Class:Azure.Security.KeyVault.Certificates.ContactList
Assembly:Azure.Security.KeyVault.Certificates
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Certificates\src\ContactList.cs
Covered lines:24
Uncovered lines:2
Coverable lines:26
Total lines:78
Line coverage:92.3% (24 of 26)
Covered branches:9
Total branches:10
Branch coverage:90% (9 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor()-100%100%
.ctor(...)-100%100%
ToList()-50%50%
Azure.Security.KeyVault.IJsonDeserializable.ReadProperties(...)-100%100%
Azure.Security.KeyVault.IJsonSerializable.WriteProperties(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Text.Json;
 7
 8namespace Azure.Security.KeyVault.Certificates
 9{
 10    internal class ContactList : IJsonDeserializable, IJsonSerializable
 11    {
 12        private const string ContactsPropertyName = "contacts";
 13
 214        private static readonly JsonEncodedText s_contactsPropertyNameBytes = JsonEncodedText.Encode(ContactsPropertyNam
 15
 16        private IEnumerable<CertificateContact> _contacts;
 17
 818        public ContactList()
 19        {
 20
 821        }
 22
 423        public ContactList(IEnumerable<CertificateContact> contacts)
 24        {
 425            _contacts = contacts;
 426        }
 27
 28        public IList<CertificateContact> ToList()
 29        {
 830            if (!(_contacts is IList<CertificateContact> ret))
 31            {
 032                ret = _contacts.ToList();
 33
 034                _contacts = ret;
 35            }
 36
 837            return ret;
 38        }
 39
 40        void IJsonDeserializable.ReadProperties(JsonElement json)
 41        {
 842            var contacts = new List<CertificateContact>();
 43
 844            if (json.TryGetProperty(ContactsPropertyName, out JsonElement contactsElement))
 45            {
 4846                foreach (JsonElement entry in contactsElement.EnumerateArray())
 47                {
 1648                    var contact = new CertificateContact();
 49
 1650                    ((IJsonDeserializable)contact).ReadProperties(entry);
 51
 1652                    contacts.Add(contact);
 53                }
 54            }
 55
 856            _contacts = contacts;
 857        }
 58
 59        void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
 60        {
 461            if (_contacts != null)
 62            {
 463                json.WriteStartArray(s_contactsPropertyNameBytes);
 64
 2465                foreach (CertificateContact contact in _contacts)
 66                {
 867                    json.WriteStartObject();
 68
 869                    ((IJsonSerializable)contact).WriteProperties(json);
 70
 871                    json.WriteEndObject();
 72                }
 73
 474                json.WriteEndArray();
 75            }
 476        }
 77    }
 78}