public async Task PublishAsync_should_throw_when_message_null() { var executor = NSubstitute.Substitute.For <IKafkaPublisherExecutor>(); var factory = NSubstitute.Substitute.For <IQueueReferenceFactory>(); var sut = new KafkaPublisher(executor, factory); await Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.PublishAsync(null)); }
public async Task PublishAsync_should_throw_when_publish_fails() { var message = DummyMessage.New(); var queueRefs = new QueueReferences("lorem", "ipsum"); var executor = NSubstitute.Substitute.For <IKafkaPublisherExecutor>(); executor.PublishAsync(message, queueRefs.TopicName, null, Arg.Any <CancellationToken>()) .Returns(new DeliveryReport <Guid, byte[]>() { Status = PersistenceStatus.NotPersisted }); var factory = NSubstitute.Substitute.For <IQueueReferenceFactory>(); factory.Create(message).ReturnsForAnyArgs(queueRefs); var sut = new KafkaPublisher(executor, factory); await Assert.ThrowsAsync <InvalidOperationException>(async() => await sut.PublishAsync(message)); }
public async Task PublishAsync_publish_message() { var message = DummyMessage.New(); var queueRefs = new QueueReferences("lorem", "ipsum"); var executor = NSubstitute.Substitute.For <IKafkaPublisherExecutor>(); executor.PublishAsync(message, queueRefs.TopicName, null, Arg.Any <CancellationToken>()) .Returns(new DeliveryReport <Guid, byte[]>() { Status = PersistenceStatus.Persisted }); var factory = NSubstitute.Substitute.For <IQueueReferenceFactory>(); factory.Create(message).ReturnsForAnyArgs(queueRefs); var sut = new KafkaPublisher(executor, factory); await sut.PublishAsync(message); await executor.Received(1) .PublishAsync(message, queueRefs.TopicName); }