< Summary

Class:Azure.Security.KeyVault.Keys.KeyAttributes
Assembly:Azure.Security.KeyVault.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\KeyAttributes.cs
Covered lines:33
Uncovered lines:1
Coverable lines:34
Total lines:93
Line coverage:97% (33 of 34)
Covered branches:42
Total branches:44
Branch coverage:95.4% (42 of 44)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
get_Enabled()-100%100%
get_NotBefore()-100%100%
get_ExpiresOn()-100%100%
get_CreatedOn()-100%100%
get_UpdatedOn()-0%100%
get_RecoverableDays()-100%100%
get_RecoveryLevel()-100%100%
get_ShouldSerialize()-100%50%
ReadProperties(...)-100%100%
WriteProperties(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\KeyAttributes.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.Keys
 8{
 9    internal struct KeyAttributes
 10    {
 11        private const string EnabledPropertyName = "enabled";
 12        private const string NotBeforePropertyName = "nbf";
 13        private const string ExpiresPropertyName = "exp";
 14        private const string CreatedPropertyName = "created";
 15        private const string UpdatedPropertyName = "updated";
 16        private const string RecoverableDaysPropertyName = "recoverableDays";
 17        private const string RecoveryLevelPropertyName = "recoveryLevel";
 18
 219        private static readonly JsonEncodedText s_enabledPropertyNameBytes = JsonEncodedText.Encode(EnabledPropertyName)
 220        private static readonly JsonEncodedText s_notBeforePropertyNameBytes = JsonEncodedText.Encode(NotBeforePropertyN
 221        private static readonly JsonEncodedText s_expiresPropertyNameBytes = JsonEncodedText.Encode(ExpiresPropertyName)
 22
 147223        public bool? Enabled { get; set; }
 24
 104025        public DateTimeOffset? NotBefore { get; set; }
 26
 120627        public DateTimeOffset? ExpiresOn { get; set; }
 28
 67229        public DateTimeOffset? CreatedOn { get; internal set; }
 30
 031        public DateTimeOffset? UpdatedOn { get; internal set; }
 32
 20233        public int? RecoverableDays { get; internal set; }
 34
 102035        public string RecoveryLevel { get; internal set; }
 36
 3637        internal bool ShouldSerialize => Enabled.HasValue && NotBefore.HasValue && ExpiresOn.HasValue;
 38
 39        internal void ReadProperties(JsonElement json)
 40        {
 747241            foreach (JsonProperty prop in json.EnumerateObject())
 42            {
 304443                switch (prop.Name)
 44                {
 45                    case EnabledPropertyName:
 68846                        Enabled = prop.Value.GetBoolean();
 68847                        break;
 48                    case NotBeforePropertyName:
 849                        NotBefore = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
 850                        break;
 51                    case ExpiresPropertyName:
 5252                        ExpiresOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
 5253                        break;
 54                    case CreatedPropertyName:
 68855                        CreatedOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
 68856                        break;
 57                    case UpdatedPropertyName:
 68858                        UpdatedOn = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
 68859                        break;
 60                    case RecoverableDaysPropertyName:
 22461                        RecoverableDays = prop.Value.GetInt32();
 22462                        break;
 63                    case RecoveryLevelPropertyName:
 68864                        RecoveryLevel = prop.Value.GetString();
 65                        break;
 66                }
 67            }
 69268        }
 69
 70        internal void WriteProperties(Utf8JsonWriter json)
 71        {
 7672            if (Enabled.HasValue)
 73            {
 7674                json.WriteBoolean(s_enabledPropertyNameBytes, Enabled.Value);
 75            }
 76
 7677            if (NotBefore.HasValue)
 78            {
 479                json.WriteNumber(s_notBeforePropertyNameBytes, NotBefore.Value.ToUnixTimeSeconds());
 80            }
 81
 7682            if (ExpiresOn.HasValue)
 83            {
 4084                json.WriteNumber(s_expiresPropertyNameBytes, ExpiresOn.Value.ToUnixTimeSeconds());
 85            }
 86
 87            // Created is read-only don't serialize
 88            // Updated is read-only don't serialize
 89            // RecoverableDays is read-only don't serialize
 90            // RecoveryLevel is read-only don't serialize
 7691        }
 92    }
 93}