Ejemplo n.º 1
0
        public async Task CanSendValidMessageAsync()
        {
            // Arrange
            var topicName  = "A";
            var producer   = new Mock <IProducer <Null, string> >();
            var serializer = new Mock <Abstractions.Serialization.ISerializer <IOutboxMessage> >();
            var options    = new Mock <IOptions <KafkaOutboxSenderOptions> >();

            options.Setup(x => x.Value).Returns(new KafkaOutboxSenderOptions()
            {
                TopicName = topicName
            });
            var logger  = new Mock <ILogger <KafkaOutboxSender> >();
            var sender  = new KafkaOutboxSender(producer.Object, serializer.Object, options.Object, logger.Object);
            var token   = new CancellationTokenSource();
            var message = new Mock <IOutboxMessage>();

            var jsonStr = "test";

            serializer.Setup(x => x.Serialize(message.Object)).Returns(jsonStr);


            // Act
            var exception = await Record.ExceptionAsync(async() => await sender.SendAsync(message.Object, token.Token));

            // Assert
            exception.Should().BeNull();
            serializer.Verify(x => x.Serialize(message.Object), Times.Once);
            producer.Verify(x => x.ProduceAsync(topicName, It.Is <Message <Null, string> >(x => x.Value == jsonStr), token.Token), Times.Once);
        }
Ejemplo n.º 2
0
        public async Task CantSendNullMessageAsync()
        {
            // Arrange
            var producer   = new Mock <IProducer <Null, string> >();
            var serializer = new Mock <Abstractions.Serialization.ISerializer <IOutboxMessage> >();
            var options    = new Mock <IOptions <KafkaOutboxSenderOptions> >();

            options.Setup(x => x.Value).Returns(new KafkaOutboxSenderOptions()
            {
                TopicName = "A"
            });
            var logger = new Mock <ILogger <KafkaOutboxSender> >();
            var sender = new KafkaOutboxSender(producer.Object, serializer.Object, options.Object, logger.Object);
            var token  = new CancellationTokenSource();

            // Act
            var exception = await Record.ExceptionAsync(async() => await sender.SendAsync(null !, token.Token));

            // Assert
            exception.Should().NotBeNull().And.BeOfType <ArgumentNullException>();
        }