< Summary

Class:Azure.Security.KeyVault.Certificates.MergeCertificateOptions
Assembly:Azure.Security.KeyVault.Certificates
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Certificates\src\MergeCertificateOptions.cs
Covered lines:20
Uncovered lines:9
Coverable lines:29
Total lines:97
Line coverage:68.9% (20 of 29)
Covered branches:6
Total branches:10
Branch coverage:60% (6 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor(...)-100%100%
get_Name()-100%100%
get_X509Certificates()-100%100%
get_Enabled()-0%100%
get_Tags()-0%100%
Azure.Security.KeyVault.IJsonSerializable.WriteProperties(...)-53.33%60%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Text.Json;
 7using System.Threading;
 8using Azure.Core;
 9
 10namespace Azure.Security.KeyVault.Certificates
 11{
 12    /// <summary>
 13    /// Options for certificates to be merged into Azure Key Vault.
 14    /// </summary>
 15    public class MergeCertificateOptions : IJsonSerializable
 16    {
 217        private static readonly JsonEncodedText s_attributesPropertyNameBytes = JsonEncodedText.Encode("attributes");
 218        private static readonly JsonEncodedText s_enabledPropertyNameBytes = JsonEncodedText.Encode("enabled");
 219        private static readonly JsonEncodedText s_tagsPropertyNameBytes = JsonEncodedText.Encode("tags");
 220        private static readonly JsonEncodedText s_x5cPropertyNameBytes = JsonEncodedText.Encode("x5c");
 21
 22        private Dictionary<string, string> _tags;
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="MergeCertificateOptions"/> class.
 26        /// </summary>
 27        /// <param name="name">The name of the certificate.</param>
 28        /// <param name="x509Certificates">The certificate or certificate chain to merge.</param>
 29        /// <exception cref="ArgumentException"><paramref name="name"/> is empty.</exception>
 30        /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="x509Certificates"/> is nu
 431        public MergeCertificateOptions(string name, IEnumerable<byte[]> x509Certificates)
 32        {
 433            Argument.AssertNotNullOrEmpty(name, nameof(name));
 434            Argument.AssertNotNull(x509Certificates, nameof(x509Certificates));
 35
 436            Name = name;
 437            X509Certificates = x509Certificates;
 438        }
 39
 40        /// <summary>
 41        /// Gets the name of the certificate.
 42        /// </summary>
 843        public string Name { get; }
 44
 45        /// <summary>
 46        /// Gets the certificate or certificate chain to merge.
 47        /// </summary>
 848        public IEnumerable<byte[]> X509Certificates { get; }
 49
 50        /// <summary>
 51        /// Gets or sets a value indicating whether the merged certificate should be enabled. If null, the server defaul
 52        /// </summary>
 053        public bool? Enabled { get; set; }
 54
 55        /// <summary>
 56        /// Gets the tags to be applied to the merged certificate. Although this collection cannot be set, it can be mod
 57        ///  or initialized with a <see href="https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-str
 58        /// </summary>
 059        public IDictionary<string, string> Tags => LazyInitializer.EnsureInitialized(ref _tags);
 60
 61        void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
 62        {
 463            if (Enabled.HasValue)
 64            {
 065                json.WriteStartObject(s_attributesPropertyNameBytes);
 66
 067                json.WriteBoolean(s_enabledPropertyNameBytes, Enabled.Value);
 68
 069                json.WriteEndObject();
 70            }
 71
 472            if (!_tags.IsNullOrEmpty())
 73            {
 074                json.WriteStartObject(s_tagsPropertyNameBytes);
 75
 076                foreach (KeyValuePair<string, string> kvp in _tags)
 77                {
 078                    json.WriteString(kvp.Key, kvp.Value);
 79                }
 80
 081                json.WriteEndObject();
 82            }
 83
 484            if (X509Certificates != null)
 85            {
 486                json.WriteStartArray(s_x5cPropertyNameBytes);
 87
 2488                foreach (byte[] x509certificate in X509Certificates)
 89                {
 890                    json.WriteBase64StringValue(x509certificate);
 91                }
 92
 493                json.WriteEndArray();
 94            }
 495        }
 96    }
 97}