public void DisposeShouldNotDisposeProducerIfProduceHasNotBeenCalled() { var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder>(); var mockProducer = new Mock <IProducer <string, string> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var sut = new KafkaMessageProducer(stubMessageProducerBuilder.Object); sut.Dispose(); mockProducer.Verify(x => x.Dispose(), Times.Never); }
public async Task DisposeShouldDisposeProducerIfProduceHasBeenCalled() { var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder>(); var mockProducer = new Mock <IProducer <string, string> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var fakeMessage = new FakeMessage("some-key-id", "some-property-value"); var sut = new KafkaMessageProducer(stubMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage.Key, fakeMessage, CancellationToken.None); sut.Dispose(); mockProducer.Verify(x => x.Dispose()); }
public async Task ProduceShouldProduceMessageWithSerialisedMessage() { var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder>(); var mockProducer = new Mock <IProducer <string, string> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var fakeMessage = new FakeMessage("some-key-id", "some-property-value"); var sut = new KafkaMessageProducer(stubMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage.Key, fakeMessage, CancellationToken.None); mockProducer.Verify(x => x.ProduceAsync(It.IsAny <string>(), It.Is <Message <string, string> >(i => i.Value == JsonConvert.SerializeObject(fakeMessage)), It.IsAny <CancellationToken>())); }
public async Task ProduceShouldProduceMessageWithCorrectKey() { const string expectedMessageKey = "some-key-id"; var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder>(); var mockProducer = new Mock <IProducer <string, string> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var fakeMessage = new FakeMessage(expectedMessageKey, "some-property-value"); var sut = new KafkaMessageProducer(stubMessageProducerBuilder.Object); await sut.ProduceAsync(expectedMessageKey, fakeMessage, CancellationToken.None); mockProducer.Verify(x => x.ProduceAsync(It.IsAny <string>(), It.Is <Message <string, string> >(i => i.Key == expectedMessageKey), It.IsAny <CancellationToken>())); }
public async Task ProduceShouldUseASingleProducerForMultipleRequests() { var mockMessageProducerBuilder = new Mock <IKafkaProducerBuilder>(); var stubProducer = new Mock <IProducer <string, string> >(); mockMessageProducerBuilder .Setup(x => x.Build()) .Returns(stubProducer.Object); var fakeMessage = new FakeMessage("some-key-id", "some-property-value"); var sut = new KafkaMessageProducer(mockMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage.Key, fakeMessage, CancellationToken.None); await sut.ProduceAsync(fakeMessage.Key, fakeMessage, CancellationToken.None); await sut.ProduceAsync(fakeMessage.Key, fakeMessage, CancellationToken.None); mockMessageProducerBuilder.Verify(x => x.Build(), Times.Once); }
public async Task ProduceShouldProduceMessageTypeAsHeader() { var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder>(); var mockProducer = new Mock <IProducer <string, string> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var expectedMessageType = typeof(FakeMessage).AssemblyQualifiedName; var fakeMessage = new FakeMessage("some-key-id", "some-property-value"); var sut = new KafkaMessageProducer(stubMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage.Key, fakeMessage, CancellationToken.None); mockProducer.Verify(x => x.ProduceAsync(It.IsAny <string>(), It.Is <Message <string, string> >(i => Encoding.UTF8.GetString(i.Headers.GetLastBytes("message-type")) == expectedMessageType), It.IsAny <CancellationToken>())); }
public async Task Dispose_ShouldDisposeProducerIfProduceHasBeenCalled() { //Arrange var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder <FakeAvro> >(); var stubLogger = Mock.Of <ILogger <KafkaMessageProducer <FakeAvro> > >(); var mockProducer = new Mock <IProducer <string, FakeAvro> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var fakeMessage = new FakeMessage("some-property-value"); //Act var sut = new KafkaMessageProducer <FakeAvro>(stubLogger, stubMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage, "key", CancellationToken.None); sut.Dispose(); //Asset mockProducer.Verify(x => x.Dispose()); }
public async Task Produce_ShouldProduceMessageWithCorrectKey() { //Arrange const string expectedMessageKey = "some-key-id"; var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder <FakeAvro> >(); var stubLogger = Mock.Of <ILogger <KafkaMessageProducer <FakeAvro> > >(); var mockProducer = new Mock <IProducer <string, FakeAvro> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var fakeMessage = new FakeMessage("fake-property-value"); //Act var sut = new KafkaMessageProducer <FakeAvro>(stubLogger, stubMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage, expectedMessageKey, CancellationToken.None); //Assert mockProducer.Verify(x => x.ProduceAsync(It.IsAny <string>(), It.Is <Message <string, FakeAvro> >(i => i.Key == expectedMessageKey), It.IsAny <CancellationToken>())); }
public async Task Produce_ShouldUseASingleProducerForMultipleRequests() { //Arrange var mockMessageProducerBuilder = new Mock <IKafkaProducerBuilder <FakeAvro> >(); var stubLogger = Mock.Of <ILogger <KafkaMessageProducer <FakeAvro> > >(); var mockProducer = new Mock <IProducer <string, FakeAvro> >(); mockMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var fakeMessage = new FakeMessage("some-property-value"); //Act var sut = new KafkaMessageProducer <FakeAvro>(stubLogger, mockMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage, "key", CancellationToken.None); await sut.ProduceAsync(fakeMessage, "key", CancellationToken.None); await sut.ProduceAsync(fakeMessage, "key", CancellationToken.None); //Assert mockMessageProducerBuilder.Verify(x => x.Build(), Times.Once); }
public async Task Produce_ShouldProduceMessageTypeAsHeader() { //Arrange var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder <FakeAvro> >(); var stubLogger = Mock.Of <ILogger <KafkaMessageProducer <FakeAvro> > >(); var mockProducer = new Mock <IProducer <string, FakeAvro> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var expectedMessageType = typeof(FakeMessage).AssemblyQualifiedName; var fakeMessage = new FakeMessage("some-property-value"); //Act var sut = new KafkaMessageProducer <FakeAvro>(stubLogger, stubMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage, "key", CancellationToken.None); //Assert mockProducer.Verify(x => x.ProduceAsync(It.IsAny <string>(), It.Is <Message <string, FakeAvro> >(i => Encoding.UTF8.GetString(i.Headers.GetLastBytes("message-type")) == expectedMessageType), It.IsAny <CancellationToken>())); }
public async Task Produce_ShouldProduceMessageWithCorrectTopic() { //Arrange const string expectedTopic = "fake-messages"; var stubMessageProducerBuilder = new Mock <IKafkaProducerBuilder <FakeAvro> >(); var stubLogger = Mock.Of <ILogger <KafkaMessageProducer <FakeAvro> > >(); var mockProducer = new Mock <IProducer <string, FakeAvro> >(); stubMessageProducerBuilder .Setup(x => x.Build()) .Returns(mockProducer.Object); var fakeMessage = new FakeMessage("fake-property-value"); //Act var sut = new KafkaMessageProducer <FakeAvro>(stubLogger, stubMessageProducerBuilder.Object); await sut.ProduceAsync(fakeMessage, "key", CancellationToken.None); //Arrange mockProducer.Verify(x => x.ProduceAsync(expectedTopic, It.IsAny <Message <string, FakeAvro> >(), It.IsAny <CancellationToken>())); }
protected NonTransactionalKafkaOutbox(KafkaMessageProducer kafkaMessageProducer, NonTransactionalOutboxes outboxes) : base(outboxes) =>
public OutboxMessageKafkaPublisher(KafkaMessageProducer kafkaMessageProducer) =>