public async Task SendEnumerableEnsuresNotClosed() { var producer = new AmqpEventHubProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), Mock.Of <EventHubRetryPolicy>()); await producer.CloseAsync(CancellationToken.None); Assert.That(async() => await producer.SendAsync(Enumerable.Empty <EventData>(), new SendOptions(), CancellationToken.None), Throws.InstanceOf <EventHubsClientClosedException>()); }
public void CloseRespectsTheCancellationToken() { var producer = new AmqpEventHubProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubRetryPolicy>()); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.That(async() => await producer.CloseAsync(cancellationSource.Token), Throws.InstanceOf <TaskCanceledException>(), "Cancellation should trigger the appropriate exception."); Assert.That(producer.Closed, Is.False, "Cancellation should have interrupted closing and left the producer in an open state."); }
public async Task CloseMarksTheProducerAsClosed() { var producer = new AmqpEventHubProducer("aHub", "0", Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubRetryPolicy>()); Assert.That(producer.Closed, Is.False, "The producer should not be closed on creation"); await producer.CloseAsync(CancellationToken.None); Assert.That(producer.Closed, Is.True, "The producer should be marked as closed after closing"); }