public void CreatePartitionReceiverCreatesDefaultWhenNoOptionsArePassed() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expectedOptions = new ReceiverOptions { Retry = clientOptions.Retry, DefaultMaximumReceiveWaitTime = clientOptions.DefaultTimeout }; var expectedPartition = "56767"; var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); var receiver = mockClient.CreateReceiver(expectedPartition); var actualOptions = mockClient.ReceiverOptions; Assert.That(receiver.PartitionId, Is.EqualTo(expectedPartition), "The partition should match."); Assert.That(actualOptions, Is.Not.Null, "The receiver options should have been set."); Assert.That(actualOptions.BeginReceivingAt.Offset, Is.EqualTo(expectedOptions.BeginReceivingAt.Offset), "The beginning position to receive should match."); Assert.That(actualOptions.ConsumerGroup, Is.EqualTo(expectedOptions.ConsumerGroup), "The consumer groups should match."); Assert.That(actualOptions.ExclusiveReceiverPriority, Is.EqualTo(expectedOptions.ExclusiveReceiverPriority), "The exclusive priorities 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 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 CreateConsumerCreatesDefaultWhenOptionsAreNotSet() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expectedOptions = new EventHubConsumerOptions { OwnerLevel = 251, Identifier = "Bob", PrefetchCount = 600, Retry = clientOptions.Retry, DefaultMaximumReceiveWaitTime = clientOptions.DefaultTimeout }; var expectedConsumerGroup = "SomeGroup"; var expectedPartition = "56767"; var expectedPosition = EventPosition.FromSequenceNumber(123); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateConsumer(expectedConsumerGroup, expectedPartition, expectedPosition, expectedOptions); var actualOptions = mockClient.ConsumerOptions; Assert.That(actualOptions, Is.Not.Null, "The consumer options should have been set."); Assert.That(actualOptions, Is.Not.SameAs(expectedOptions), "A clone of the options should have been made."); 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 CreateProducerCreatesDefaultWhenOptionsAreNotSet() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var producerOptions = new EventHubProducerOptions { PartitionId = "123", Retry = null, Timeout = TimeSpan.Zero }; var expected = new EventHubProducerOptions { PartitionId = producerOptions.PartitionId, Retry = clientOptions.Retry, Timeout = clientOptions.DefaultTimeout }; var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateProducer(producerOptions); Assert.That(mockClient.ProducerOptions, Is.Not.Null, "The producer options should have been set."); Assert.That(mockClient.ProducerOptions, Is.Not.SameAs(producerOptions), "The options should have been cloned."); Assert.That(mockClient.ProducerOptions.PartitionId, Is.EqualTo(expected.PartitionId), "The partition identifiers should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)mockClient.ProducerOptions.Retry, (ExponentialRetry)expected.Retry), "The retries should match."); Assert.That(mockClient.ProducerOptions.TimeoutOrDefault, Is.EqualTo(expected.TimeoutOrDefault), "The timeouts should match."); }
public void CreateConsumerCreatesDefaultWhenNoOptionsArePassed() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expectedOptions = new EventHubConsumerOptions { Retry = clientOptions.Retry, DefaultMaximumReceiveWaitTime = clientOptions.DefaultTimeout }; var expectedConsumerGroup = EventHubConsumer.DefaultConsumerGroup; var expectedPartition = "56767"; var expectedPosition = EventPosition.FromEnqueuedTime(DateTime.Parse("2015-10-27T12:00:00Z")); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new ReadableOptionsMock(connectionString, clientOptions); mockClient.CreateConsumer(expectedConsumerGroup, expectedPartition, expectedPosition); var actualOptions = mockClient.ConsumerOptions; Assert.That(actualOptions, Is.Not.Null, "The consumer options should have been set."); 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 CloneProducesACopy() { var options = new ReceiverOptions { ConsumerGroup = "custom$consumer", BeginReceivingAt = EventPosition.FromOffset(65), ExclusiveReceiverPriority = 99, Retry = new ExponentialRetry(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(5), 6), DefaultMaximumReceiveWaitTime = TimeSpan.FromMinutes(65), Identifier = "an_event_receiver" }; var clone = options.Clone(); Assert.That(clone, Is.Not.Null, "The clone should not be null."); Assert.That(clone.ConsumerGroup, Is.EqualTo(options.ConsumerGroup), "The consumer group of the clone should match."); Assert.That(clone.BeginReceivingAt, Is.EqualTo(options.BeginReceivingAt), "The position to begin reading events of the clone should match."); Assert.That(clone.ExclusiveReceiverPriority, Is.EqualTo(options.ExclusiveReceiverPriority), "The exclusive priority of the clone should match."); Assert.That(clone.DefaultMaximumReceiveWaitTime, Is.EqualTo(options.DefaultMaximumReceiveWaitTime), "The default maximum wait time of the clone should match."); Assert.That(clone.Identifier, Is.EqualTo(options.Identifier), "The identifier of the clone should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)clone.Retry, (ExponentialRetry)options.Retry), "The retry of the clone should be considered equal."); Assert.That(clone.Retry, Is.Not.SameAs(options.Retry), "The retry of the clone should be a copy, not the same instance."); }
public void CreateEventSenderCreatesDefaultWhenNoOptionsArePassed() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expected = new SenderOptions { Retry = clientOptions.Retry, Timeout = clientOptions.DefaultTimeout }; var actual = default(SenderOptions); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new Mock <EventHubClient>(connectionString, clientOptions) { CallBase = true }; mockClient .Protected() .Setup <EventSender>("BuildEventSender", ItExpr.IsAny <ConnectionType>(), ItExpr.IsAny <string>(), ItExpr.IsAny <SenderOptions>()) .Returns(Mock.Of <EventSender>()) .Callback <ConnectionType, string, SenderOptions>((type, path, options) => actual = options); mockClient.Object.CreateSender(); Assert.That(actual, Is.Not.Null, "The sender options should have been set."); Assert.That(actual.PartitionId, Is.EqualTo(expected.PartitionId), "The partition identifiers should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)actual.Retry, (ExponentialRetry)expected.Retry), "The retries should match."); Assert.That(actual.TimeoutOrDefault, Is.EqualTo(expected.TimeoutOrDefault), "The timeouts should match."); }
public void CloneProducesACopy() { var retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(2), 123); var clone = retry.Clone() as ExponentialRetry; Assert.That(clone, Is.Not.Null, "The clone should not be null."); Assert.That(ExponentialRetry.HaveSameConfiguration(clone, retry), Is.True, "The clone should be considered equal."); Assert.That(clone, Is.Not.SameAs(retry), "The clone should be a copy, not the same instance."); }
public void TransportClientReceivesClonedOptions(ReadableOptionsMock client, EventHubClientOptions constructorOptions, string constructorDescription) { var options = client.TransportClientOptions; Assert.That(options, Is.Not.Null, $"The { constructorDescription } constructor should have set the options."); Assert.That(options, Is.Not.SameAs(constructorOptions), $"The { constructorDescription } constructor should have cloned the options."); Assert.That(options.TransportType, Is.EqualTo(constructorOptions.TransportType), $"The { constructorDescription } constructor should have the correct connection type."); Assert.That(options.DefaultTimeout, Is.EqualTo(constructorOptions.DefaultTimeout), $"The { constructorDescription } constructor should have the correct default timeout."); Assert.That(options.Proxy, Is.EqualTo(constructorOptions.Proxy), $"The { constructorDescription } constructor should have the correct proxy."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)options.Retry, (ExponentialRetry)constructorOptions.Retry), $"The { constructorDescription } constructor should have the correct retry."); }
public void ConstructorCreatesDefaultOptions(ReadableOptionsMock client, string constructorDescription) { var defaultOptions = new EventHubClientOptions(); var options = client.ClientOptions; Assert.That(options, Is.Not.Null, $"The { constructorDescription } constructor should have set default options."); Assert.That(options, Is.Not.SameAs(defaultOptions), $"The { constructorDescription } constructor should not have the same options instance."); Assert.That(options.TransportType, Is.EqualTo(defaultOptions.TransportType), $"The { constructorDescription } constructor should have the correct connection type."); Assert.That(options.DefaultTimeout, Is.EqualTo(defaultOptions.DefaultTimeout), $"The { constructorDescription } constructor should have the correct default timeout."); Assert.That(options.Proxy, Is.EqualTo(defaultOptions.Proxy), $"The { constructorDescription } constructor should have the correct proxy."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)options.Retry, (ExponentialRetry)defaultOptions.Retry), $"The { constructorDescription } constructor should have the correct retry."); }
public void ConstructorClonesOptions(EventHubClient client, EventHubClientOptions constructorOptions, string constructorDescription) { var options = (EventHubClientOptions)typeof(EventHubClient) .GetProperty("ClientOptions", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(client); Assert.That(options, Is.Not.Null, $"The { constructorDescription } constructor should have set the options."); Assert.That(options, Is.Not.SameAs(constructorOptions), $"The { constructorDescription } constructor should have cloned the options."); Assert.That(options.ConnectionType, Is.EqualTo(constructorOptions.ConnectionType), $"The { constructorDescription } constructor should have the correct connection type."); Assert.That(options.DefaultTimeout, Is.EqualTo(constructorOptions.DefaultTimeout), $"The { constructorDescription } constructor should have the correct default timeout."); Assert.That(options.Proxy, Is.EqualTo(constructorOptions.Proxy), $"The { constructorDescription } constructor should have the correct proxy."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)options.Retry, (ExponentialRetry)constructorOptions.Retry), $"The { constructorDescription } constructor should have the correct retry."); }
public void CreatePartitionReceiverCreatesDefaultWhenOptionsAreNotSet() { var clientOptions = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), 5), DefaultTimeout = TimeSpan.FromHours(24) }; var expectedOptions = new ReceiverOptions { BeginReceivingAt = EventPosition.FromOffset(65), ConsumerGroup = "SomeGroup", ExclusiveReceiverPriority = 251, Identifier = "Bob", PrefetchCount = 600, Retry = clientOptions.Retry, DefaultMaximumReceiveWaitTime = clientOptions.DefaultTimeout }; var expectedPartition = "56767"; var actualOptions = default(ReceiverOptions); var actualPartition = default(string); var connectionString = "Endpoint=value.com;SharedAccessKeyName=[value];SharedAccessKey=[value];EntityPath=[value]"; var mockClient = new Mock <EventHubClient>(connectionString, clientOptions) { CallBase = true }; mockClient .Protected() .Setup <PartitionReceiver>("BuildPartitionReceiver", ItExpr.IsAny <ConnectionType>(), ItExpr.IsAny <string>(), ItExpr.IsAny <string>(), ItExpr.IsAny <ReceiverOptions>()) .Returns(Mock.Of <PartitionReceiver>()) .Callback <ConnectionType, string, string, ReceiverOptions>((type, path, partition, options) => { actualOptions = options; actualPartition = partition; }); mockClient.Object.CreatePartitionReceiver(expectedPartition, expectedOptions); Assert.That(actualPartition, Is.EqualTo(expectedPartition), "The partition should match."); Assert.That(actualOptions, Is.Not.Null, "The receiver options should have been set."); Assert.That(actualOptions, Is.Not.SameAs(expectedOptions), "A clone of the options should have been made."); Assert.That(actualOptions.BeginReceivingAt.Offset, Is.EqualTo(expectedOptions.BeginReceivingAt.Offset), "The beginning position to receive should match."); Assert.That(actualOptions.ConsumerGroup, Is.EqualTo(expectedOptions.ConsumerGroup), "The consumer groups should match."); Assert.That(actualOptions.ExclusiveReceiverPriority, Is.EqualTo(expectedOptions.ExclusiveReceiverPriority), "The exclusive priorities 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 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 CloneProducesACopy() { var options = new EventHubProducerOptions { PartitionId = "some_partition_id_123", Retry = new ExponentialRetry(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(5), 6), Timeout = TimeSpan.FromMinutes(65) }; var clone = options.Clone(); Assert.That(clone, Is.Not.Null, "The clone should not be null."); Assert.That(clone.PartitionId, Is.EqualTo(options.PartitionId), "The partition identifier of the clone should match."); Assert.That(clone.Timeout, Is.EqualTo(options.Timeout), "The timeout of the clone should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)clone.Retry, (ExponentialRetry)options.Retry), "The retry of the clone should be considered equal."); Assert.That(clone.Retry, Is.Not.SameAs(options.Retry), "The retry of the clone should be a copy, not the same instance."); }
public void CloneProducesACopy() { var options = new EventHubConsumerOptions { OwnerLevel = 99, Retry = new ExponentialRetry(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(5), 6), DefaultMaximumReceiveWaitTime = TimeSpan.FromMinutes(65), Identifier = "an_event_consumer" }; var clone = options.Clone(); Assert.That(clone, Is.Not.Null, "The clone should not be null."); Assert.That(clone.OwnerLevel, Is.EqualTo(options.OwnerLevel), "The ownerlevel of the clone should match."); Assert.That(clone.DefaultMaximumReceiveWaitTime, Is.EqualTo(options.DefaultMaximumReceiveWaitTime), "The default maximum wait time of the clone should match."); Assert.That(clone.Identifier, Is.EqualTo(options.Identifier), "The identifier of the clone should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)clone.Retry, (ExponentialRetry)options.Retry), "The retry of the clone should be considered equal."); Assert.That(clone.Retry, Is.Not.SameAs(options.Retry), "The retry of the clone should be a copy, not the same instance."); }
public void CloneProducesACopy() { var options = new EventHubClientOptions { Retry = new ExponentialRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), 3), TransportType = TransportType.AmqpWebSockets, DefaultTimeout = TimeSpan.FromDays(1), Proxy = Mock.Of <IWebProxy>() }; var clone = options.Clone(); Assert.That(clone, Is.Not.Null, "The clone should not be null."); Assert.That(clone.TransportType, Is.EqualTo(options.TransportType), "The connection type of the clone should match."); Assert.That(clone.DefaultTimeout, Is.EqualTo(options.DefaultTimeout), "The default timeout of the clone should match."); Assert.That(clone.Proxy, Is.EqualTo(options.Proxy), "The proxy of the clone should match."); Assert.That(ExponentialRetry.HaveSameConfiguration((ExponentialRetry)clone.Retry, (ExponentialRetry)options.Retry), Is.True, "The retry of the clone should be considered equal."); Assert.That(clone.Retry, Is.Not.SameAs(options.Retry), "The retry of the clone should be a copy, not the same instance."); }
public void HaveSameConfigurationRecognizesEquivilentConfiguration(ExponentialRetry first, ExponentialRetry second, string description) { Assert.That(ExponentialRetry.HaveSameConfiguration(first, second), Is.True, $"{ description } should be considered the same configuration."); }
public void HaveSameConfigurationRecognizesDifferentConfiguration(ExponentialRetry first, ExponentialRetry second, string description) { Assert.That(ExponentialRetry.HaveSameConfiguration(first, second), Is.False, $"{ description } should be considered different configurations."); }