< Summary

Class:Azure.Security.KeyVault.Secrets.DeletedSecret
Assembly:Azure.Security.KeyVault.Secrets
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Secrets\src\DeletedSecret.cs
Covered lines:14
Uncovered lines:12
Coverable lines:26
Total lines:89
Line coverage:53.8% (14 of 26)
Covered branches:7
Total branches:16
Branch coverage:43.7% (7 of 16)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-0%100%
.ctor(...)-100%100%
get_RecoveryId()-100%50%
set_RecoveryId(...)-0%0%
get_DeletedOn()-100%100%
get_ScheduledPurgeDate()-100%100%
ReadProperty(...)-100%100%
WriteProperties(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Secrets\src\DeletedSecret.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    /// Represents a Key Vault secret that has been deleted, allowing it to be recovered, if needed.
 11    /// </summary>
 12    public class DeletedSecret : KeyVaultSecret
 13    {
 14        private const string RecoveryIdPropertyName = "recoveryId";
 15        private const string DeletedOnPropertyName = "deletedDate";
 16        private const string ScheduledPurgeDatePropertyName = "scheduledPurgeDate";
 17
 018        private static readonly JsonEncodedText s_recoveryIdPropertyNameBytes = JsonEncodedText.Encode(RecoveryIdPropert
 019        private static readonly JsonEncodedText s_deletedOnPropertyNameBytes = JsonEncodedText.Encode(DeletedOnPropertyN
 020        private static readonly JsonEncodedText s_scheduledPurgeDatePropertyNameBytes = JsonEncodedText.Encode(Scheduled
 21
 22        private string _recoveryId;
 23
 43624        internal DeletedSecret(SecretProperties properties = null) : base(properties)
 25        {
 43626        }
 27
 28        /// <summary>
 29        /// Gets a <see cref="Uri"/> of the deleted secret that can be used to recover it.
 30        /// </summary>
 31        public Uri RecoveryId
 32        {
 22033            get => _recoveryId is null ? null : new Uri(_recoveryId);
 034            internal set => _recoveryId = value?.ToString();
 35        }
 36
 37        /// <summary>
 38        /// Gets a <see cref="DateTimeOffset"/> indicating when the secret was deleted.
 39        /// </summary>
 44440        public DateTimeOffset? DeletedOn { get; internal set; }
 41
 42        /// <summary>
 43        /// Gets a <see cref="DateTimeOffset"/> for when the deleted secret will be purged.
 44        /// </summary>
 44445        public DateTimeOffset? ScheduledPurgeDate { get; internal set; }
 46
 47        internal override void ReadProperty(JsonProperty prop)
 48        {
 218849            switch (prop.Name)
 50            {
 51                case RecoveryIdPropertyName:
 43652                    _recoveryId = prop.Value.GetString();
 43653                    break;
 54
 55                case DeletedOnPropertyName:
 43656                    DeletedOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
 43657                    break;
 58
 59                case ScheduledPurgeDatePropertyName:
 43660                    ScheduledPurgeDate = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
 43661                    break;
 62
 63                default:
 88064                    base.ReadProperty(prop);
 65                    break;
 66            }
 88067        }
 68
 69        internal override void WriteProperties(Utf8JsonWriter json)
 70        {
 071            base.WriteProperties(json);
 72
 073            if (RecoveryId != null)
 74            {
 075                json.WriteString(s_recoveryIdPropertyNameBytes, RecoveryId.ToString());
 76            }
 77
 078            if (DeletedOn.HasValue)
 79            {
 080                json.WriteNumber(s_deletedOnPropertyNameBytes, DeletedOn.Value.ToUnixTimeSeconds());
 81            }
 82
 083            if (ScheduledPurgeDate.HasValue)
 84            {
 085                json.WriteNumber(s_scheduledPurgeDatePropertyNameBytes, ScheduledPurgeDate.Value.ToUnixTimeSeconds());
 86            }
 087        }
 88    }
 89}