< Summary

Class:Azure.Security.KeyVault.Secrets.KeyVaultSecret
Assembly:Azure.Security.KeyVault.Secrets
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Secrets\src\KeyVaultSecret.cs
Covered lines:25
Uncovered lines:0
Coverable lines:25
Total lines:90
Line coverage:100% (25 of 25)
Covered branches:10
Total branches:10
Branch coverage:100% (10 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
get_Id()-100%100%
get_Name()-100%100%
get_Properties()-100%100%
get_Value()-100%100%
ReadProperty(...)-100%100%
WriteProperties(...)-100%100%
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.Secrets\src\KeyVaultSecret.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.Secrets
 8{
 9    /// <summary>
 10    /// <see cref="KeyVaultSecret"/> is the resource consisting of a value and its <see cref="Properties"/>.
 11    /// </summary>
 12    public class KeyVaultSecret : IJsonDeserializable, IJsonSerializable
 13    {
 14        private const string ValuePropertyName = "value";
 15
 416        private static readonly JsonEncodedText s_valuePropertyNameBytes = JsonEncodedText.Encode(ValuePropertyName);
 17
 118418        internal KeyVaultSecret(SecretProperties properties = null)
 19        {
 118420            Properties = properties ?? new SecretProperties();
 118421        }
 22
 23        /// <summary>
 24        /// Initializes a new instance of the <see cref="KeyVaultSecret"/> class.
 25        /// </summary>
 26        /// <param name="name">The name of the secret.</param>
 27        /// <param name="value">The value of the secret.</param>
 28        /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception>
 29        /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="value"/> is null.</except
 74030        public KeyVaultSecret(string name, string value)
 31        {
 74032            Properties = new SecretProperties(name);
 73233            Value = value ?? throw new ArgumentNullException(nameof(value));
 72834        }
 35
 36        /// <summary>
 37        /// Gets the secret identifier.
 38        /// </summary>
 1000439        public Uri Id => Properties.Id;
 40
 41        /// <summary>
 42        /// Gets the the name of the secret.
 43        /// </summary>
 3378044        public string Name => Properties.Name;
 45
 46        /// <summary>
 47        /// Gets additional properties of the <see cref="KeyVaultSecret"/>.
 48        /// </summary>
 4778849        public SecretProperties Properties { get; }
 50
 51        /// <summary>
 52        /// Gets the value of the secret.
 53        /// </summary>
 303254        public string Value { get; internal set; }
 55
 56        internal virtual void ReadProperty(JsonProperty prop)
 57        {
 302058            switch (prop.Name)
 59            {
 60                case ValuePropertyName:
 74861                    Value = prop.Value.GetString();
 74862                    break;
 63
 64                default:
 227265                    Properties.ReadProperty(prop);
 66                    break;
 67            }
 227268        }
 69
 70        internal virtual void WriteProperties(Utf8JsonWriter json)
 71        {
 72872            if (Value != null)
 73            {
 72874                json.WriteString(s_valuePropertyNameBytes, Value);
 75            }
 76
 72877            Properties.WriteProperties(json);
 72878        }
 79
 80        void IJsonDeserializable.ReadProperties(JsonElement json)
 81        {
 1102482            foreach (JsonProperty prop in json.EnumerateObject())
 83            {
 432884                ReadProperty(prop);
 85            }
 118486        }
 87
 72888        void IJsonSerializable.WriteProperties(Utf8JsonWriter json) => WriteProperties(json);
 89    }
 90}