< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Endpoint()-100%100%
get_EventHubName()-100%100%
get_SharedAccessKeyName()-100%100%
get_SharedAccessKey()-100%100%
.ctor(...)-100%100%
Validate(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5
 6namespace Azure.Messaging.EventHubs.Core
 7{
 8    /// <summary>
 9    ///   The set of properties that comprise a connection string from the
 10    ///   Azure portal.
 11    /// </summary>
 12    ///
 13    internal struct ConnectionStringProperties
 14    {
 15        /// <summary>
 16        ///   The endpoint to be used for connecting to the Event Hubs namespace.
 17        /// </summary>
 18        ///
 19        /// <value>The endpoint address, including protocol, from the connection string.</value>
 20        ///
 35221        public Uri Endpoint { get; }
 22
 23        /// <summary>
 24        ///   The name of the specific Event Hub instance under the associated Event Hubs namespace.
 25        /// </summary>
 26        ///
 35027        public string EventHubName { get; }
 28
 29        /// <summary>
 30        ///   The name of the shared access key, either for the Event Hubs namespace
 31        ///   or the Event Hub.
 32        /// </summary>
 33        ///
 32234        public string SharedAccessKeyName { get; }
 35
 36        /// <summary>
 37        ///   The value of the shared access key, either for the Event Hubs namespace
 38        ///   or the Event Hub.
 39        /// </summary>
 40        ///
 31441        public string SharedAccessKey { get; }
 42
 43        /// <summary>
 44        ///   Initializes a new instance of the <see cref="ConnectionStringProperties"/> structure.
 45        /// </summary>
 46        ///
 47        /// <param name="endpoint">The endpoint of the Event Hubs namespace.</param>
 48        /// <param name="eventHubName">The name of the specific Event Hub under the namespace.</param>
 49        /// <param name="sharedAccessKeyName">The name of the shared access key, to use authorization.</param>
 50        /// <param name="sharedAccessKey">The shared access key to use for authorization.</param>
 51        ///
 52        public ConnectionStringProperties(Uri endpoint,
 53                                          string eventHubName,
 54                                          string sharedAccessKeyName,
 55                                          string sharedAccessKey)
 56        {
 21857            Endpoint = endpoint;
 21858            EventHubName = eventHubName;
 21859            SharedAccessKeyName = sharedAccessKeyName;
 21860            SharedAccessKey = sharedAccessKey;
 21861        }
 62
 63        /// <summary>
 64        ///   Performs the actions needed to validate the set of connection string properties for connecting to the
 65        ///   Event Hubs service.
 66        /// </summary>
 67        ///
 68        /// <param name="explicitEventHubName">The name of the Event Hub that was explicitly passed independent of the c
 69        /// <param name="connectionStringArgumentName">The name of the argument associated with the connection string; t
 70        ///
 71        /// <exception cref="ArgumentException">In the case that the properties violate an invariant or otherwise repres
 72        ///
 73        public void Validate(string explicitEventHubName,
 74                             string connectionStringArgumentName)
 75        {
 76            // The Event Hub name may only be specified in one of the possible forms, either as part of the
 77            // connection string or as a stand-alone parameter, but not both.  If specified in both to the same
 78            // value, then do not consider this a failure.
 79
 21880            if ((!string.IsNullOrEmpty(explicitEventHubName))
 21881                && (!string.IsNullOrEmpty(EventHubName))
 21882                && (!string.Equals(explicitEventHubName, EventHubName, StringComparison.InvariantCultureIgnoreCase)))
 83            {
 1084                throw new ArgumentException(Resources.OnlyOneEventHubNameMayBeSpecified, connectionStringArgumentName);
 85            }
 86
 87            // Ensure that each of the needed components are present for connecting.
 88
 20889            if ((string.IsNullOrEmpty(explicitEventHubName)) && (string.IsNullOrEmpty(EventHubName))
 20890                || (string.IsNullOrEmpty(Endpoint?.Host))
 20891                || (string.IsNullOrEmpty(SharedAccessKeyName))
 20892                || (string.IsNullOrEmpty(SharedAccessKey)))
 93            {
 4894                throw new ArgumentException(Resources.MissingConnectionInformation, connectionStringArgumentName);
 95            }
 16096        }
 97    }
 98}