Пример #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>());
        }
Пример #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>());
        }
Пример #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>());
        }
Пример #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");
        }
Пример #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));
        }
Пример #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));
        }
Пример #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));
        }
Пример #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");
        }