public void ConsumersAndProducersAreCached() { EventHubOptions options = new EventHubOptions(); var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", ConnectionString)); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration), new AzureEventSourceLogForwarder(new NullLoggerFactory())); var producer = factory.GetEventHubProducerClient("k1", "connection"); var consumer = factory.GetEventHubConsumerClient("k1", "connection", null); var producer2 = factory.GetEventHubProducerClient("k1", "connection"); var consumer2 = factory.GetEventHubConsumerClient("k1", "connection", null); Assert.AreSame(producer, producer2); Assert.AreSame(consumer, consumer2); }
public void RespectsConnectionOptionsForProducer(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { CustomEndpointAddress = testEndpoint, ClientRetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 } }; var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration), new AzureEventSourceLogForwarder(new NullLoggerFactory())); var producer = factory.GetEventHubProducerClient(expectedPathName, "connection"); EventHubConnection connection = (EventHubConnection)typeof(EventHubProducerClient).GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(producer); EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connection); Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress); Assert.AreEqual(expectedPathName, producer.EventHubName); EventHubProducerClientOptions producerOptions = (EventHubProducerClientOptions)typeof(EventHubProducerClient).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(producer); Assert.AreEqual(10, producerOptions.RetryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, producer.EventHubName); }
public void GetEventHubClient_AddsConnection(string expectedPathName, string connectionString) { EventHubOptions options = new EventHubOptions(); var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration), new AzureEventSourceLogForwarder(new NullLoggerFactory())); var client = factory.GetEventHubProducerClient(expectedPathName, "connection"); Assert.AreEqual(expectedPathName, client.EventHubName); }
public void EntityPathInConnectionString(string expectedPathName, string connectionString) { EventHubOptions options = new EventHubOptions(); // Test sender options.AddSender("k1", connectionString); var configuration = CreateConfiguration(); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration)); var client = factory.GetEventHubProducerClient("k1", null); Assert.AreEqual(expectedPathName, client.EventHubName); }
public void CreatesClientsFromConfigWithConnectionString() { EventHubOptions options = new EventHubOptions(); var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", ConnectionString)); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration), new AzureEventSourceLogForwarder(new NullLoggerFactory())); var producer = factory.GetEventHubProducerClient("k1", "connection"); var consumer = factory.GetEventHubConsumerClient("k1", "connection", null); var host = factory.GetEventProcessorHost("k1", "connection", null); Assert.AreEqual("k1", producer.EventHubName); Assert.AreEqual("k1", consumer.EventHubName); Assert.AreEqual("k1", host.EventHubName); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", producer.FullyQualifiedNamespace); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", consumer.FullyQualifiedNamespace); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", host.FullyQualifiedNamespace); }
public void CreatesClientsFromConfigWithFullyQualifiedNamespace() { EventHubOptions options = new EventHubOptions(); var componentFactoryMock = new Mock <AzureComponentFactory>(); componentFactoryMock.Setup(c => c.CreateTokenCredential( It.Is <IConfiguration>(c => c["fullyQualifiedNamespace"] != null))) .Returns(new DefaultAzureCredential()); var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection:fullyQualifiedNamespace", "test89123-ns-x.servicebus.windows.net")); var factory = new EventHubClientFactory(configuration, componentFactoryMock.Object, Options.Create(options), new DefaultNameResolver(configuration), new AzureEventSourceLogForwarder(new NullLoggerFactory())); var producer = factory.GetEventHubProducerClient("k1", "connection"); var consumer = factory.GetEventHubConsumerClient("k1", "connection", null); var host = factory.GetEventProcessorHost("k1", "connection", null); Assert.AreEqual("k1", producer.EventHubName); Assert.AreEqual("k1", consumer.EventHubName); Assert.AreEqual("k1", host.EventHubName); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", producer.FullyQualifiedNamespace); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", consumer.FullyQualifiedNamespace); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", host.FullyQualifiedNamespace); }