< Summary

Class:Azure.Messaging.EventHubs.Core.ClientLibraryInformation
Assembly:Azure.Messaging.EventHubs
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\src\Core\ClientLibraryInformation.cs
Covered lines:18
Uncovered lines:0
Coverable lines:18
Total lines:103
Line coverage:100% (18 of 18)
Covered branches:6
Total branches:8
Branch coverage:75% (6 of 8)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Current()-100%100%
get_Product()-100%100%
get_Version()-100%100%
get_Framework()-100%100%
get_Platform()-100%100%
get_UserAgent()-100%100%
.ctor()-100%50%
EnumerateProperties()-100%100%
GetTelemetryName(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\src\Core\ClientLibraryInformation.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.ComponentModel;
 6using System.Linq;
 7using System.Reflection;
 8using System.Runtime.Versioning;
 9
 10namespace Azure.Messaging.EventHubs.Core
 11{
 12    /// <summary>
 13    ///   The set of information describing the active version of the
 14    ///   client library.
 15    /// </summary>
 16    ///
 17    internal sealed class ClientLibraryInformation
 18    {
 19        /// <summary>
 20        ///   The current set of information.
 21        /// </summary>
 22        ///
 3223        public static ClientLibraryInformation Current { get; } = new ClientLibraryInformation();
 24
 25        /// <summary>
 26        ///   The name of the client library product.
 27        ///  </summary>
 28        ///
 2029        public string Product { get; }
 30
 31        /// <summary>
 32        ///   The version of the client library.
 33        /// </summary>
 34        ///
 2035        public string Version { get; }
 36
 37        /// <summary>
 38        ///   The version of the framework on which the client library was
 39        ///   built.
 40        /// </summary>
 41        ///
 2042        public string Framework { get; }
 43
 44        /// <summary>
 45        ///  The name of the platform on which the client library is currently running.
 46        /// </summary>
 47        ///
 2048        public string Platform { get; }
 49
 50        /// <summary>
 51        ///  The client library information, formatted in the standard form used by SDK
 52        ///  user agents when interacting with Azure services.
 53        /// </summary>
 54        ///
 55        [Description("user-agent")]
 1056        public string UserAgent => $"azsdk-net-{ Product }/{ Version } ({ Framework }; { Platform })";
 57
 58        /// <summary>
 59        ///   Prevents a default instance of the <see cref="ClientLibraryInformation"/> class from being created.
 60        /// </summary>
 61        ///
 262        private ClientLibraryInformation()
 63        {
 264            Assembly assembly = typeof(ClientLibraryInformation).Assembly;
 65
 266            Product = $"{ nameof(Messaging) }.{ nameof(EventHubs) }";
 267            Version = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
 268            Framework = assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;
 69
 70#if FullNetFx
 71            Platform = Environment.OSVersion.VersionString;
 72#else
 273            Platform = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
 74#endif
 275        }
 76
 77        /// <summary>
 78        ///   Enumerates the client library properties, normalizing the property names.
 79        /// </summary>
 80        ///
 81        /// <returns>An enumerable set of the properties, with name and value.</returns>
 82        ///
 83        public IEnumerable<KeyValuePair<string, string>> EnumerateProperties() =>
 684            typeof(ClientLibraryInformation)
 685                .GetProperties(BindingFlags.Instance | BindingFlags.Public)
 3686                .Select(property => new KeyValuePair<string, string>(GetTelemetryName(property), (string)property.GetVal
 87
 88        /// <summary>
 89        ///   Gets the name of the property, as it should appear in telemetry
 90        ///   information.
 91        /// </summary>
 92        ///
 93        /// <param name="property">The property to consider.</param>
 94        ///
 95        /// <returns>The name of the property for use as telemetry for the client library.</returns>
 96        ///
 97        private static string GetTelemetryName(PropertyInfo property)
 98        {
 3099            string name = property.GetCustomAttribute<DescriptionAttribute>(false)?.Description;
 30100            return ((string.IsNullOrEmpty(name)) ? property.Name : name).ToLowerInvariant();
 101        }
 102    }
 103}