/// <summary> /// It tries to read the <see cref="EventHubsNamespaceConnectionString"/> environment variable. /// If not found, it creates a new namespace on Azure. /// </summary> /// /// <returns>The active Event Hubs namespace for this test run.</returns> /// private static NamespaceProperties EnsureEventHubsNamespace() { if (!string.IsNullOrEmpty(EventHubsNamespaceConnectionString.Value)) { var parsed = ConnectionStringParser.Parse(EventHubsNamespaceConnectionString.Value); return(new NamespaceProperties ( parsed.Endpoint.Host.Substring(0, parsed.Endpoint.Host.IndexOf('.')), EventHubsNamespaceConnectionString.Value.Replace($";EntityPath={ parsed.EventHubName }", string.Empty), shouldRemoveAtCompletion: false )); } return(Task .Run(async() => await EventHubScope.CreateNamespaceAsync().ConfigureAwait(false)) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
/// <summary> /// Ensures that an Event Hubs namespace is available for the test run, using one if provided by the /// <see cref="EventHubsNamespaceConnectionStringEnvironmentVariable" /> or creating a new Azure resource specific /// to the current run. /// </summary> /// /// <returns>The active Event Hubs namespace for this test run.</returns> /// private NamespaceProperties EnsureEventHubsNamespace() { var environmentConnectionString = GetOptionalVariable(EventHubsNamespaceConnectionStringEnvironmentVariable); if (!string.IsNullOrEmpty(environmentConnectionString)) { var parsed = EventHubsConnectionStringProperties.Parse(environmentConnectionString); return(new NamespaceProperties ( parsed.FullyQualifiedNamespace.Substring(0, parsed.FullyQualifiedNamespace.IndexOf('.')), environmentConnectionString.Replace($";EntityPath={ parsed.EventHubName }", string.Empty), shouldRemoveAtCompletion: false )); } return(Task .Run(async() => await EventHubScope.CreateNamespaceAsync().ConfigureAwait(false)) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
/// <summary> /// Requests creation of an Event Hubs namespace to use for a specific test run, /// transforming the asynchronous request into a synchronous one that can be used with /// lazy instantiation. /// </summary> /// /// <returns>The active Event Hubs namespace for this test run./returns> /// private static EventHubScope.NamespaceProperties CreateNamespace() => Task .Run(async() => await EventHubScope.CreateNamespaceAsync().ConfigureAwait(false)) .ConfigureAwait(false) .GetAwaiter() .GetResult();