示例#1
0
        public void CloseRespectsTheCancellationToken()
        {
            var consumer = new AmqpConsumer("aHub", "$DEFAULT", "0", EventPosition.Earliest, true, null, null, Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubsRetryPolicy>());

            using var cancellationSource = new CancellationTokenSource();

            cancellationSource.Cancel();
            Assert.That(async() => await consumer.CloseAsync(cancellationSource.Token), Throws.InstanceOf <TaskCanceledException>(), "Cancellation should trigger the appropriate exception.");
            Assert.That(consumer.IsClosed, Is.False, "Cancellation should have interrupted closing and left the consumer in an open state.");
        }
示例#2
0
        public async Task CloseMarksTheConsumerAsClosed()
        {
            var consumer = new AmqpConsumer("aHub", "$DEFAULT", "0", EventPosition.Earliest, true, null, null, Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubsRetryPolicy>());

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

            await consumer.CloseAsync(CancellationToken.None);

            Assert.That(consumer.IsClosed, Is.True, "The consumer should be marked as closed after closing");
        }
示例#3
0
        public async Task ReceiveAsyncValidatesClosed()
        {
            var eventHub           = "eventHubName";
            var consumerGroup      = "$DEFAULT";
            var partition          = "3";
            var eventPosition      = EventPosition.FromOffset(123);
            var options            = new EventHubConsumerClientOptions();
            var retryPolicy        = new BasicRetryPolicy(new EventHubsRetryOptions());
            var retriableException = new EventHubsException(true, "Test");
            var mockConverter      = new Mock <AmqpMessageConverter>();
            var mockCredential     = new Mock <TokenCredential>();
            var mockScope          = new Mock <AmqpConnectionScope>();

            using var cancellationSource = new CancellationTokenSource();

            var consumer = new AmqpConsumer(eventHub, consumerGroup, partition, eventPosition, true, null, null, mockScope.Object, Mock.Of <AmqpMessageConverter>(), retryPolicy);
            await consumer.CloseAsync(cancellationSource.Token);

            Assert.That(async() => await consumer.ReceiveAsync(100, null, cancellationSource.Token), Throws.InstanceOf <EventHubsClientClosedException>());
        }