< Summary

Class:Azure.Security.KeyVault.Certificates.LifetimeAction
Assembly:Azure.Security.KeyVault.Certificates
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Certificates\src\LifetimeAction.cs
Covered lines:29
Uncovered lines:6
Coverable lines:35
Total lines:117
Line coverage:82.8% (29 of 35)
Covered branches:13
Total branches:16
Branch coverage:81.2% (13 of 16)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor(...)-0%100%
.ctor()-100%100%
get_DaysBeforeExpiry()-0%100%
get_LifetimePercentage()-100%100%
get_Action()-100%100%
FromJsonObject(...)-100%100%
Azure.Security.KeyVault.IJsonDeserializable.ReadProperties(...)-88.89%83.33%
Azure.Security.KeyVault.IJsonSerializable.WriteProperties(...)-90%75%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Text.Json;
 5
 6namespace Azure.Security.KeyVault.Certificates
 7{
 8    /// <summary>
 9    /// An action to be executed at a prescribed time in a certificates lifecycle
 10    /// </summary>
 11    public class LifetimeAction : IJsonSerializable, IJsonDeserializable
 12    {
 13        private const string TriggerPropertyName = "trigger";
 14        private const string ActionPropertyName = "action";
 15        private const string LifetimePercentagePropertyName = "lifetime_percentage";
 16        private const string DaysBeforeExpiryPropertyName = "days_before_expiry";
 17        private const string ActionTypePropertyName = "action_type";
 18
 219        private static readonly JsonEncodedText s_triggerPropertyNameBytes = JsonEncodedText.Encode(TriggerPropertyName)
 220        private static readonly JsonEncodedText s_actionPropertyNameBytes = JsonEncodedText.Encode(ActionPropertyName);
 221        private static readonly JsonEncodedText s_lifetimePercentagePropertyNameBytes = JsonEncodedText.Encode(LifetimeP
 222        private static readonly JsonEncodedText s_daysBeforeExpiryPropertyNameBytes = JsonEncodedText.Encode(DaysBeforeE
 223        private static readonly JsonEncodedText s_actionTypePropertyNameBytes = JsonEncodedText.Encode(ActionTypePropert
 24
 25        /// <summary>
 26        /// Initializes a new instance of the <see cref="LifetimeAction"/> class.
 27        /// </summary>
 28        /// <param name="action">The <see cref="CertificatePolicyAction"/> to be performed.</param>
 029        public LifetimeAction(CertificatePolicyAction action)
 30        {
 031            Action = action;
 032        }
 33
 7034        private LifetimeAction()
 35        {
 7036        }
 37
 38        /// <summary>
 39        /// Gets or sets the action should be performed the specified number of days before the certificate will expire.
 40        /// </summary>
 041        public int? DaysBeforeExpiry { get; set; }
 42
 43        /// <summary>
 44        /// Gets or sets the action should be performed when the certificate reaches the specified percentage of its lif
 45        /// </summary>
 7646        public int? LifetimePercentage { get; set; }
 47
 48        /// <summary>
 49        /// Gets the <see cref="CertificatePolicyAction"/> to be performed.
 50        /// </summary>
 7451        public CertificatePolicyAction Action { get; private set; }
 52
 53        internal static LifetimeAction FromJsonObject(JsonElement json)
 54        {
 7055            var action = new LifetimeAction();
 56
 7057            ((IJsonDeserializable)action).ReadProperties(json);
 58
 7059            return action;
 60        }
 61
 62        void IJsonDeserializable.ReadProperties(JsonElement json)
 63        {
 42064            foreach (JsonProperty prop in json.EnumerateObject())
 65            {
 14066                switch (prop.Name)
 67                {
 68                    case TriggerPropertyName:
 28069                        foreach (JsonProperty triggerProp in prop.Value.EnumerateObject())
 70                        {
 7071                            switch (triggerProp.Name)
 72                            {
 73                                case LifetimePercentagePropertyName:
 7074                                    LifetimePercentage = triggerProp.Value.GetInt32();
 7075                                    break;
 76
 77                                case DaysBeforeExpiryPropertyName:
 078                                    DaysBeforeExpiry = triggerProp.Value.GetInt32();
 79                                    break;
 80                            }
 81                        }
 82                        break;
 83
 84                    case ActionPropertyName:
 7085                        Action = prop.Value.GetProperty(ActionTypePropertyName).GetString();
 86                        break;
 87                }
 88            }
 7089        }
 90
 91        void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
 92        {
 93            // trigger
 294            json.WriteStartObject(s_triggerPropertyNameBytes);
 95
 296            if (DaysBeforeExpiry.HasValue)
 97            {
 098                json.WriteNumber(s_daysBeforeExpiryPropertyNameBytes, DaysBeforeExpiry.Value);
 99            }
 100
 2101            if (LifetimePercentage.HasValue)
 102            {
 2103                json.WriteNumber(s_lifetimePercentagePropertyNameBytes, LifetimePercentage.Value);
 104            }
 105
 2106            json.WriteEndObject();
 107
 108            // action
 2109            json.WriteStartObject(s_actionPropertyNameBytes);
 110
 2111            json.WriteString(s_actionTypePropertyNameBytes, Action.ToString());
 112
 2113            json.WriteEndObject();
 114
 2115        }
 116    }
 117}