< Summary

Class:Azure.Security.KeyVault.Certificates.SubjectAlternativeNames
Assembly:Azure.Security.KeyVault.Certificates
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Certificates\src\SubjectAlternativeNames.cs
Covered lines:25
Uncovered lines:9
Coverable lines:34
Total lines:115
Line coverage:73.5% (25 of 34)
Covered branches:16
Total branches:30
Branch coverage:53.3% (16 of 30)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor()-100%100%
get_DnsNames()-100%100%
get_Emails()-100%100%
get_UserPrincipalNames()-100%100%
get_IsEmpty()-100%100%
Azure.Security.KeyVault.IJsonDeserializable.ReadProperties(...)-0%0%
Azure.Security.KeyVault.IJsonSerializable.WriteProperties(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Collections.ObjectModel;
 6using System.Text.Json;
 7using System.Threading;
 8
 9namespace Azure.Security.KeyVault.Certificates
 10{
 11    /// <summary>
 12    /// A collection of subject alternative names (SANs) for a X.509 certificate. SANs can be DNS entries, emails, or un
 13    /// </summary>
 14    public class SubjectAlternativeNames : IJsonSerializable, IJsonDeserializable
 15    {
 16        private const string DnsPropertyName = "dns_names";
 17        private const string EmailsPropertyName = "emails";
 18        private const string UpnsPropertyName = "upns";
 19
 220        private static readonly JsonEncodedText s_dnsPropertyNameBytes = JsonEncodedText.Encode(DnsPropertyName);
 221        private static readonly JsonEncodedText s_emailsPropertyNameBytes = JsonEncodedText.Encode(EmailsPropertyName);
 222        private static readonly JsonEncodedText s_upnsPropertyNameBytes = JsonEncodedText.Encode(UpnsPropertyName);
 23
 24        private Collection<string> _dnsNames;
 25        private Collection<string> _emails;
 26        private Collection<string> _userPrincipalNames;
 27
 28        /// <summary>
 29        /// Initializes a new instance of the <see cref="CertificateContact"/> class.
 30        /// </summary>
 1631        public SubjectAlternativeNames()
 32        {
 1633        }
 34
 35        /// <summary>
 36        /// Gets a collection of DNS names.
 37        /// </summary>
 1238        public IList<string> DnsNames => LazyInitializer.EnsureInitialized(ref _dnsNames);
 39
 40        /// <summary>
 41        /// Gets a collection of email addresses.
 42        /// </summary>
 643        public IList<string> Emails => LazyInitializer.EnsureInitialized(ref _emails);
 44
 45        /// <summary>
 46        /// Gets a collection of user principal names (UPNs).
 47        /// </summary>
 448        public IList<string> UserPrincipalNames => LazyInitializer.EnsureInitialized(ref _userPrincipalNames);
 49
 1650        internal bool IsEmpty => _dnsNames.IsNullOrEmpty() && _emails.IsNullOrEmpty() && _userPrincipalNames.IsNullOrEmp
 51
 52        void IJsonDeserializable.ReadProperties(JsonElement json)
 53        {
 054            foreach (JsonProperty prop in json.EnumerateObject())
 55            {
 056                switch (prop.Name)
 57                {
 58                    case DnsPropertyName:
 059                        foreach (JsonElement element in prop.Value.EnumerateArray())
 60                        {
 061                            DnsNames.Add(element.ToString());
 62                        }
 63                        break;
 64
 65                    case EmailsPropertyName:
 066                        foreach (JsonElement element in prop.Value.EnumerateArray())
 67                        {
 068                            Emails.Add(element.ToString());
 69                        }
 70                        break;
 71
 72                    case UpnsPropertyName:
 073                        foreach (JsonElement element in prop.Value.EnumerateArray())
 74                        {
 075                            UserPrincipalNames.Add(element.ToString());
 76                        }
 77                        break;
 78                }
 79            }
 080        }
 81
 82        void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
 83        {
 1084            if (!_dnsNames.IsNullOrEmpty())
 85            {
 486                json.WriteStartArray(s_dnsPropertyNameBytes);
 2087                foreach (string dnsName in _dnsNames)
 88                {
 689                    json.WriteStringValue(dnsName);
 90                }
 491                json.WriteEndArray();
 92            }
 93
 1094            if (!_emails.IsNullOrEmpty())
 95            {
 696                json.WriteStartArray(s_emailsPropertyNameBytes);
 2497                foreach (string email in _emails)
 98                {
 699                    json.WriteStringValue(email);
 100                }
 6101                json.WriteEndArray();
 102            }
 103
 10104            if (!_userPrincipalNames.IsNullOrEmpty())
 105            {
 4106                json.WriteStartArray(s_upnsPropertyNameBytes);
 16107                foreach (string userPrincipalName in _userPrincipalNames)
 108                {
 4109                    json.WriteStringValue(userPrincipalName);
 110                }
 4111                json.WriteEndArray();
 112            }
 10113        }
 114    }
 115}