< Summary

Class:Microsoft.Azure.ApplicationInsights.Query.Models.BaseMetricInfo
Assembly:Microsoft.Azure.ApplicationInsights.Query
File(s):C:\Git\azure-sdk-for-net\sdk\applicationinsights\Microsoft.Azure.ApplicationInsights.Query\src\Customized\Models\BaseMetricInfo.cs
Covered lines:0
Uncovered lines:23
Coverable lines:23
Total lines:84
Line coverage:0% (0 of 23)
Covered branches:0
Total branches:14
Branch coverage:0% (0 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_MetricId()-0%100%
get_MetricValues()-0%100%
InitMetricFields(...)-0%0%
GetAggregatedValue(...)-0%0%
GetSum()-0%100%
GetAverage()-0%100%
GetMin()-0%100%
GetMax()-0%100%
GetCount()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\applicationinsights\Microsoft.Azure.ApplicationInsights.Query\src\Customized\Models\BaseMetricInfo.cs

#LineLine coverage
 1using Newtonsoft.Json.Linq;
 2using System.Collections.Generic;
 3using System.Runtime.Serialization;
 4
 5namespace Microsoft.Azure.ApplicationInsights.Query.Models
 6{
 7    public abstract class BaseMetricInfo
 8    {
 9        internal abstract IDictionary<string, object> GetAdditionalProperties();
 10
 011        public string MetricId { get; private set; } = null;
 012        public Dictionary<string, float> MetricValues { get; set; } = new Dictionary<string, float>();
 13
 14        [OnDeserialized]
 15        internal void InitMetricFields(StreamingContext context)
 16        {
 017            var additionalProperties = GetAdditionalProperties();
 18
 019            if (additionalProperties != null)
 20            {
 021                foreach (var additionalProp in additionalProperties)
 22                {
 023                    if (additionalProp.Value is object)
 24                    {
 025                        var dict = additionalProp.Value as JObject;
 026                        if (dict == null) continue;
 27
 028                        MetricId = additionalProp.Key;
 29
 030                        foreach (var prop in dict.Properties())
 31                        {
 032                            MetricValues.Add(prop.Name, prop.Value.Value<float>());
 33                        }
 34                    }
 35                }
 36            }
 037        }
 38
 39        private float? GetAggregatedValue(string aggregation)
 40        {
 041            if (MetricValues.TryGetValue(aggregation, out var value))
 42            {
 043                return value;
 44            }
 45            else
 46            {
 047                return null;
 48            }
 49        }
 50
 51        public float? GetSum()
 52        {
 053            return GetAggregatedValue("sum");
 54        }
 55
 56        public float? GetAverage()
 57        {
 058            return GetAggregatedValue("avg");
 59        }
 60
 61        public float? GetMin()
 62        {
 063            return GetAggregatedValue("min");
 64        }
 65
 66        public float? GetMax()
 67        {
 068            return GetAggregatedValue("max");
 69        }
 70
 71        public int? GetCount()
 72        {
 073            var count = GetAggregatedValue("count");
 074            if (count != null)
 75            {
 076                return (int) count;
 77            }
 78            else
 79            {
 080                return null;
 81            }
 82        }
 83    }
 84}