public void CreateConsumerInvokesTheTransportClient() { var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); var expectedPosition = EventPosition.FromOffset(65); var expectedPartition = "2123"; var expectedConsumerGroup = EventHubConsumerClient.DefaultConsumerGroupName; var expectedRetryPolicy = new EventHubsRetryOptions { MaximumRetries = 67 }.ToRetryPolicy(); var expectedTrackLastEnqueued = false; var expectedPrefetch = 99U; var expectedOwnerLevel = 123L; client.CreateTransportConsumer(expectedConsumerGroup, expectedPartition, expectedPosition, expectedRetryPolicy, expectedTrackLastEnqueued, expectedOwnerLevel, expectedPrefetch); (var actualConsumerGroup, var actualPartition, EventPosition actualPosition, var actualRetry, var actualTrackLastEnqueued, var actualOwnerLevel, var actualPrefetch) = transportClient.CreateConsumerCalledWith; Assert.That(actualPartition, Is.EqualTo(expectedPartition), "The partition should have been passed."); Assert.That(actualConsumerGroup, Is.EqualTo(expectedConsumerGroup), "The consumer groups should match."); Assert.That(actualPosition.Offset, Is.EqualTo(expectedPosition.Offset), "The event position to receive should match."); Assert.That(actualRetry, Is.SameAs(expectedRetryPolicy), "The retryPolicy should match."); Assert.That(actualOwnerLevel, Is.EqualTo(expectedOwnerLevel), "The owner levels should match."); Assert.That(actualPrefetch, Is.EqualTo(expectedPrefetch), "The prefetch counts should match."); Assert.That(actualTrackLastEnqueued, Is.EqualTo(expectedTrackLastEnqueued), "The flag for tracking the last enqueued event should match."); }
public void CreateConsumerInvokesTheTransportClient() { var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); var expectedOptions = new EventHubConsumerOptions { Retry = Retry.Default }; var expectedPosition = EventPosition.FromOffset(65); var expectedPartition = "2123"; var expectedConsumerGroup = EventHubConsumer.DefaultConsumerGroup; client.CreateConsumer(expectedConsumerGroup, expectedPartition, expectedPosition, expectedOptions); (var actualConsumerGroup, var actualPartition, var actualPosition, var actualOptions) = transportClient.CreateConsumerCalledWith; Assert.That(actualPartition, Is.EqualTo(expectedPartition), "The partition should have been passed."); Assert.That(actualConsumerGroup, Is.EqualTo(expectedConsumerGroup), "The consumer groups should match."); Assert.That(actualPosition.Offset, Is.EqualTo(expectedPosition.Offset), "The event position to receive should match."); Assert.That(actualOptions, Is.Not.Null, "The consumer options should have been set."); Assert.That(actualPosition.Offset, Is.EqualTo(expectedPosition.Offset), "The event position to receive should match."); Assert.That(actualOptions.OwnerLevel, Is.EqualTo(expectedOptions.OwnerLevel), "The owner levels should match."); Assert.That(actualOptions.Identifier, Is.EqualTo(expectedOptions.Identifier), "The identifiers should match."); Assert.That(actualOptions.PrefetchCount, Is.EqualTo(expectedOptions.PrefetchCount), "The prefetch counts should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)actualOptions.Retry, (ExponentialRetry)expectedOptions.Retry), "The retries should match."); Assert.That(actualOptions.MaximumReceiveWaitTimeOrDefault, Is.EqualTo(expectedOptions.MaximumReceiveWaitTimeOrDefault), "The wait times should match."); }
public void ContructorWithConnectionStringUsingSharedAccessSignatureCreatesTheCorrectTransportCredential() { var sasToken = new SharedAccessSignature("hub", "root", "abc1234").Value; var client = new InjectableTransportClientMock(Mock.Of <TransportClient>(), $"Endpoint=sb://not-real.servicebus.windows.net/;EntityPath=fake;SharedAccessSignature={ sasToken }"); Assert.That(client.TransportClientCredential, Is.Not.Null, "The transport client should have been given a credential."); Assert.That(client.TransportClientCredential.GetToken(default, default).Token, Is.EqualTo(sasToken), "The transport client credential should use the provided SAS token.");
public void CloseClosesTheTransportClient() { var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); client.Close(); Assert.That(transportClient.WasCloseCalled, Is.True); }
public async Task GetPropertiesAsyncInvokesTheTransportClient() { var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); await client.GetPropertiesAsync(CancellationToken.None); Assert.That(transportClient.WasGetPropertiesCalled, Is.True); }
public async Task GetPartitionPropertiesAsyncInvokesTheTransportClient() { var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); var expectedId = "BB33"; await client.GetPartitionPropertiesAsync(expectedId); Assert.That(transportClient.GetPartitionPropertiesCalledForId, Is.EqualTo(expectedId)); }
public void BuildResourceConstructsFromHostAndPath() { var host = "my.eventhub.com"; var path = "someHub"; var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); var expectedPath = $"/{ path.ToLowerInvariant() }"; var resource = BuildResource(client, TransportType.AmqpTcp, host, path); Assert.That(resource, Is.Not.Null.Or.Empty, "The resource should have been populated."); var uri = new Uri(resource, UriKind.Absolute); Assert.That(uri.Host, Is.EqualTo(host), "The resource should match the host."); Assert.That(uri.AbsolutePath, Is.EqualTo(expectedPath), "The resource path should match the Event Hub path."); }
public void BuildResourceNormalizesTheResource() { var host = "my.eventhub.com"; var path = "someHub/"; var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); var resource = BuildResource(client, TransportType.AmqpWebSockets, host, path); Assert.That(resource, Is.Not.Null.Or.Empty, "The resource should have been populated."); Assert.That(resource, Is.EqualTo(resource.ToLowerInvariant()), "The resource should have been normalized to lower case."); var uri = new Uri(resource, UriKind.Absolute); Assert.That(uri.AbsolutePath.StartsWith("/"), Is.True, "The resource path have been normalized to begin with a trailing slash."); Assert.That(uri.AbsolutePath.EndsWith("/"), Is.False, "The resource path have been normalized to not end with a trailing slash."); }
public void CreateProducerInvokesTheTransportClient() { var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); var expectedOptions = new EventHubProducerOptions { Retry = Retry.Default }; client.CreateProducer(expectedOptions); var actualOptions = transportClient.CreateProducerCalledWithOptions; Assert.That(actualOptions, Is.Not.Null, "The producer options should have been set."); Assert.That(actualOptions.PartitionId, Is.EqualTo(expectedOptions.PartitionId), "The partition identifiers should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)actualOptions.Retry, (ExponentialRetry)expectedOptions.Retry), "The retries should match."); Assert.That(actualOptions.TimeoutOrDefault, Is.EqualTo(expectedOptions.TimeoutOrDefault), "The timeouts should match."); }
public void CreateProducerInvokesTheTransportClient() { var transportClient = new ObservableTransportClientMock(); var client = new InjectableTransportClientMock(transportClient, "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake"); var expectedOptions = new EventHubProducerClientOptions { RetryOptions = new RetryOptions { MaximumRetries = 6, TryTimeout = TimeSpan.FromMinutes(4) } }; client.CreateTransportProducer(null, expectedOptions); Assert.That(transportClient.CreateProducerCalledWith, Is.Not.Null, "The producer options should have been set."); Assert.That(transportClient.CreateProducerCalledWith.PartitionId, Is.Null, "There should have been no partition specified."); Assert.That(transportClient.CreateProducerCalledWith.Options.RetryOptions.IsEquivalentTo(expectedOptions.RetryOptions), Is.True, "The retry options should match."); }