public async Task CreateClientPopulatesTheProxy() { var options = new EventHubClientOptions { TransportType = TransportType.AmqpWebSockets, Proxy = Mock.Of <IWebProxy>() }; var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => defaultRetry); try { Assert.That(client.WebProxy, Is.SameAs(options.Proxy), "The client should honor the proxy."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientTranslatesTheTransportType(TransportType connectionType) { var options = new EventHubClientOptions { TransportType = connectionType }; var host = "my.eventhub.com"; var eventHubPath = "some-path"; var signature = new SharedAccessSignature(options.TransportType, host, eventHubPath, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options); try { if (connectionType.ToString().ToLower().Contains("websockets")) { Assert.That(client.ConnectionStringBuilder.TransportType.ToString().ToLower(), Contains.Substring("websockets"), "The transport type should be based on WebSockets."); } else { Assert.That(client.ConnectionStringBuilder.TransportType.ToString().ToLower(), Does.Not.Contain("websockets"), "The transport type should be based on TCP."); } } finally { await client?.CloseAsync(); } }
public async Task CreateClientUsesDefaultPolicyForTheRetryPolicy() { var retryOptions = new RetryOptions { MaximumRetries = 99, MaximumDelay = TimeSpan.FromHours(72), Delay = TimeSpan.FromSeconds(27) }; var options = new EventHubClientOptions(); options.ClearRetryOptions(); var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetryPolicy = new BasicRetryPolicy(retryOptions); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => defaultRetryPolicy); try { Assert.That(client.RetryPolicy, Is.Not.Null, "The client should have a retry policy."); Assert.That(client.RetryPolicy, Is.InstanceOf <TrackOneRetryPolicy>(), "The client should always use the track one compatibility retry policy."); var clientPolicy = GetSourcePolicy((TrackOneRetryPolicy)client.RetryPolicy); Assert.That(clientPolicy, Is.SameAs(defaultRetryPolicy), "The default policy should have been used as the source policy."); } finally { await client?.CloseAsync(); } }
public void CreateFailsForUnknownCredentialType() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var credential = Mock.Of <TokenCredential>(); Assert.That(() => TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options), Throws.InstanceOf <NotImplementedException>()); }
public void CreateFailsForUnknownCredentialType() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubName = "some-path"; var credential = Mock.Of <TokenCredential>(); Assert.That(() => TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => Mock.Of <EventHubRetryPolicy>()), Throws.InstanceOf <ArgumentException>()); }
public void CreateFailsOnUnknownConnectionType() { var options = new EventHubClientOptions { TransportType = (TransportType)Int32.MinValue }; var host = "my.eventhub.com"; var eventHubPath = "some-path"; var signature = new SharedAccessSignature(TransportType.AmqpTcp, host, eventHubPath, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); Assert.That(() => TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options), Throws.InstanceOf <ArgumentException>()); }
public void CreateFailsOnUnknownConnectionType() { var options = new EventHubClientOptions { TransportType = (TransportType)Int32.MinValue }; var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); Assert.That(() => TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => defaultRetry), Throws.InstanceOf <ArgumentException>()); }
public async Task CreateClientPopulatesTheEventHubPath() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var signature = new SharedAccessSignature(options.TransportType, host, eventHubPath, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options); try { Assert.That(client.EventHubName, Is.EqualTo(eventHubPath), "The client should recognize the Event Hub path."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientTranslatesTheCredential() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var signature = new SharedAccessSignature(options.TransportType, host, eventHubPath, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options); try { Assert.That(client.InternalTokenProvider, Is.InstanceOf <TrackOneSharedAccessTokenProvider>(), "The token provider should be the track one SAS adapter."); Assert.That(((TrackOneSharedAccessTokenProvider)client.InternalTokenProvider).SharedAccessSignature.Value, Is.EqualTo(signature.Value), "The SAS should match."); } finally { await client?.CloseAsync(); } }
public async Task CreateClienCreatesTheProperClientType() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var signature = new SharedAccessSignature(options.TransportType, host, eventHubPath, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var client = TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options); try { Assert.That(client, Is.Not.Null, "The client should have been returned."); Assert.That(client, Is.InstanceOf <AmqpEventHubClient>(), "The client should be specific to the AMQP protocol."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientTranslatesTheEventHubCredential() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var resource = $"amqps://{ host }/{ eventHubPath }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new EventHubTokenCredential(Mock.Of <TokenCredential>(), resource); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options); try { Assert.That(client.InternalTokenProvider, Is.InstanceOf <TrackOneGenericTokenProvider>(), "The token provider should be the track one generic adapter."); Assert.That(((TrackOneGenericTokenProvider)client.InternalTokenProvider).Credential, Is.EqualTo(credential), "The source credential should match."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientPopulatesTheEventHubName() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => defaultRetry); try { Assert.That(client.EventHubName, Is.EqualTo(eventHubName), "The client should recognize the Event Hub path."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientTranslatesTheEventHubCredential() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var credential = new EventHubTokenCredential(Mock.Of <TokenCredential>(), resource); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => defaultRetry); try { Assert.That(client.InternalTokenProvider, Is.InstanceOf <TrackOneGenericTokenProvider>(), "The token provider should be the track one generic adapter."); Assert.That(((TrackOneGenericTokenProvider)client.InternalTokenProvider).Credential, Is.EqualTo(credential), "The source credential should match."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientFormsTheCorrectEndpoint() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubPath = "some-path"; var signature = new SharedAccessSignature(options.TransportType, host, eventHubPath, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubPath, credential, options); try { var endpoint = client.ConnectionStringBuilder.Endpoint; Assert.That(endpoint.Scheme.ToLowerInvariant(), Contains.Substring(options.TransportType.GetUriScheme().ToLowerInvariant()), "The scheme should be part of the endpoint."); Assert.That(endpoint.Host.ToLowerInvariant(), Contains.Substring(host.ToLowerInvariant()), "The host should be part of the endpoint."); Assert.That(endpoint.AbsolutePath.ToLowerInvariant(), Contains.Substring(eventHubPath.ToLowerInvariant()), "The host should be part of the endpoint."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientCreatesTheProperClientType() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); var client = TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => defaultRetry); try { Assert.That(client, Is.Not.Null, "The client should have been returned."); Assert.That(client, Is.InstanceOf <AmqpEventHubClient>(), "The client should be specific to the AMQP protocol."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientTranslatesTheSharedKeyCredential() { var options = new EventHubClientOptions(); var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var defaultRetry = Mock.Of <EventHubRetryPolicy>(); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => defaultRetry); try { Assert.That(client.InternalTokenProvider, Is.InstanceOf <TrackOneSharedAccessTokenProvider>(), "The token provider should be the track one SAS adapter."); Assert.That(((TrackOneSharedAccessTokenProvider)client.InternalTokenProvider).SharedAccessSignature.Value, Is.EqualTo(signature.Value), "The SAS should match."); } finally { await client?.CloseAsync(); } }
public async Task CreateClientUsesClientOptionsForTheRetryPolicy() { var retryOptions = new RetryOptions { MaximumRetries = 99, MaximumDelay = TimeSpan.FromHours(72), Delay = TimeSpan.FromSeconds(27) }; var options = new EventHubClientOptions { TransportType = TransportType.AmqpWebSockets, RetryOptions = retryOptions }; var host = "my.eventhub.com"; var eventHubName = "some-path"; var resource = $"amqps://{ host }/{ eventHubName }"; var signature = new SharedAccessSignature(resource, "keyName", "KEY", TimeSpan.FromHours(1)); var credential = new SharedAccessSignatureCredential(signature); var client = (AmqpEventHubClient)TrackOneEventHubClient.CreateClient(host, eventHubName, credential, options, () => Mock.Of <EventHubRetryPolicy>()); try { Assert.That(client.RetryPolicy, Is.Not.Null, "The client should have a retry policy."); var sourcePolicy = GetSourcePolicy((TrackOneRetryPolicy)client.RetryPolicy); Assert.That(sourcePolicy, Is.InstanceOf <BasicRetryPolicy>(), "The source retry policy should be a basic retry policy."); var clientPolicy = (BasicRetryPolicy)sourcePolicy; Assert.That(clientPolicy.Options.Delay, Is.EqualTo(retryOptions.Delay), "The delays should match."); Assert.That(clientPolicy.Options.MaximumDelay, Is.EqualTo(retryOptions.MaximumDelay), "The maximum delays should match."); Assert.That(clientPolicy.Options.MaximumRetries, Is.EqualTo(retryOptions.MaximumRetries), "The maximum retries should match."); Assert.That(clientPolicy.Options.TryTimeout, Is.EqualTo(retryOptions.TryTimeout), "The per-try timeouts should match."); } finally { await client?.CloseAsync(); } }