public async Task SendEnumerableEnsuresNotClosed() { var producer = new AmqpProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), Mock.Of <EventHubsRetryPolicy>()); await producer.CloseAsync(CancellationToken.None); Assert.That(async() => await producer.SendAsync(Enumerable.Empty <EventData>(), new SendOptions(), CancellationToken.None), Throws.InstanceOf <EventHubsClientClosedException>()); }
public void SendEnumerableRespectsTheCancellationTokenIfSetWhenCalled() { using CancellationTokenSource cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); var producer = new AmqpProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), Mock.Of <EventHubsRetryPolicy>()); Assert.That(async() => await producer.SendAsync(new[] { new EventData(new byte[] { 0x15 }) }, new SendOptions(), cancellationSource.Token), Throws.InstanceOf <TaskCanceledException>()); }
public void CloseRespectsTheCancellationToken() { var producer = new AmqpProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubsRetryPolicy>()); 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 AmqpProducer("aHub", "0", Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubsRetryPolicy>()); 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"); }
/// <summary> /// Sets the maximum message size for the given producer, using its /// private accessor. /// </summary> /// private static void SetMaximumMessageSize(AmqpProducer target, long value) { typeof(AmqpProducer) .GetProperty("MaximumMessageSize", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetProperty) .SetValue(target, value); }
public void SendBatchValidatesTheBatch() { var producer = new AmqpProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), Mock.Of <EventHubsRetryPolicy>()); Assert.That(async() => await producer.SendAsync(null, CancellationToken.None), Throws.ArgumentNullException); }