Exemplo n.º 1
0
        public async Task CreateProducerValidatesClosed()
        {
            using var cancellationSource = new CancellationTokenSource();

            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var client     = new AmqpClient("my.eventhub.com", "somePath", credential.Object, new EventHubConnectionOptions());
            await client.CloseAsync(cancellationSource.Token);

            Assert.That(() => client.CreateProducer(null, new EventHubProducerClientOptions()), Throws.InstanceOf <EventHubsClientClosedException>());
        }
Exemplo n.º 2
0
        public void CloseRespectsTheCancellationToken()
        {
            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var client     = new AmqpClient("my.eventhub.com", "somePath", credential.Object, new EventHubConnectionOptions());

            using var cancellationSource = new CancellationTokenSource();

            cancellationSource.Cancel();
            Assert.That(async() => await client.CloseAsync(cancellationSource.Token), Throws.InstanceOf <TaskCanceledException>());
        }
Exemplo n.º 3
0
        public async Task GetPartitionPropertiesAsyncValidatesClosed()
        {
            using var cancellationSource = new CancellationTokenSource();

            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var client     = new AmqpClient("my.eventhub.com", "somePath", credential.Object, new EventHubConnectionOptions());
            await client.CloseAsync(cancellationSource.Token);

            Assert.That(async() => await client.GetPartitionPropertiesAsync("Fred", Mock.Of <EventHubsRetryPolicy>(), cancellationSource.Token), Throws.InstanceOf <EventHubsClientClosedException>());
        }
Exemplo n.º 4
0
        public async Task CloseMarksTheClientAsClosed()
        {
            var client = new AmqpClient("my.eventhub.com", "somePath", Mock.Of <TokenCredential>(), new EventHubConnectionOptions());

            Assert.That(client.Closed, Is.False, "The client should not be closed on creation");

            await client.CloseAsync(CancellationToken.None);

            Assert.That(client.Closed, Is.True, "The client should be marked as closed after closing");
        }
Exemplo n.º 5
0
        public async Task CreateConsumerValidatesClosed()
        {
            using var cancellationSource = new CancellationTokenSource();

            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var client     = new AmqpClient("my.eventhub.com", "somePath", credential.Object, new EventHubConnectionOptions());
            await client.CloseAsync(cancellationSource.Token);

            Assert.That(() => client.CreateConsumer("group", "0", EventPosition.Earliest, Mock.Of <EventHubsRetryPolicy>(), false, null, null), Throws.InstanceOf <EventHubsException>().And.Property(nameof(EventHubsException.Reason)).EqualTo(EventHubsException.FailureReason.ClientClosed));
        }
Exemplo n.º 6
0
        public async Task GetPropertiesAsyncRespectsClosed()
        {
            using var cancellationSource = new CancellationTokenSource();

            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var client     = new AmqpClient("my.eventhub.com", "somePath", credential.Object, new EventHubConnectionOptions());
            await client.CloseAsync(cancellationSource.Token);

            Assert.That(async() => await client.GetPropertiesAsync(Mock.Of <EventHubsRetryPolicy>(), cancellationSource.Token), Throws.InstanceOf <EventHubsException>().And.Property(nameof(EventHubsException.Reason)).EqualTo(EventHubsException.FailureReason.ClientClosed));
        }
Exemplo n.º 7
0
        public async Task CreateProducerValidatesClosed()
        {
            using var cancellationSource = new CancellationTokenSource();

            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>());
            var client     = new AmqpClient("my.eventhub.com", "somePath", TimeSpan.FromDays(1), credential.Object, new EventHubConnectionOptions());
            await client.CloseAsync(cancellationSource.Token);

            Assert.That(() => client.CreateProducer(null, "", TransportProducerFeatures.None, null, Mock.Of <EventHubsRetryPolicy>()), Throws.InstanceOf <EventHubsException>().And.Property(nameof(EventHubsException.Reason)).EqualTo(EventHubsException.FailureReason.ClientClosed));
        }
Exemplo n.º 8
0
        public async Task GetPartitionPropertiesAsyncValidatesClosed()
        {
            using var cancellationSource = new CancellationTokenSource();

            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>());
            var client     = new AmqpClient("my.eventhub.com", "somePath", TimeSpan.FromDays(1), credential.Object, new EventHubConnectionOptions());
            await client.CloseAsync(cancellationSource.Token);

            Assert.That(async() => await client.GetPartitionPropertiesAsync("Fred", Mock.Of <EventHubsRetryPolicy>(), cancellationSource.Token), Throws.InstanceOf <EventHubsException>().And.Property(nameof(EventHubsException.Reason)).EqualTo(EventHubsException.FailureReason.ClientClosed));
        }
        public async Task CloseMarksTheClientAsClosed()
        {
            var credential = new Mock <EventHubTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var client     = new AmqpClient("my.eventhub.com", "somePath", credential.Object, new EventHubConnectionOptions());

            Assert.That(client.IsClosed, Is.False, "The client should not be closed on creation");

            await client.CloseAsync(CancellationToken.None);

            Assert.That(client.IsClosed, Is.True, "The client should be marked as closed after closing");
        }