< Summary

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

Metrics

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

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        ///
 021        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        ///
 027        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        ///
 034        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        ///
 041        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        {
 057            Endpoint = endpoint;
 058            EventHubName = eventHubName;
 059            SharedAccessKeyName = sharedAccessKeyName;
 060            SharedAccessKey = sharedAccessKey;
 061        }
 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
 080            if ((!string.IsNullOrEmpty(explicitEventHubName))
 081                && (!string.IsNullOrEmpty(EventHubName))
 082                && (!string.Equals(explicitEventHubName, EventHubName, StringComparison.InvariantCultureIgnoreCase)))
 83            {
 084                throw new ArgumentException(Resources.OnlyOneEventHubNameMayBeSpecified, connectionStringArgumentName);
 85            }
 86
 87            // Ensure that each of the needed components are present for connecting.
 88
 089            if ((string.IsNullOrEmpty(explicitEventHubName)) && (string.IsNullOrEmpty(EventHubName))
 090                || (string.IsNullOrEmpty(Endpoint?.Host))
 091                || (string.IsNullOrEmpty(SharedAccessKeyName))
 092                || (string.IsNullOrEmpty(SharedAccessKey)))
 93            {
 094                throw new ArgumentException(Resources.MissingConnectionInformation, connectionStringArgumentName);
 95            }
 096        }
 97    }
 98}