public async Task GivenMessage_WhenPublish_ShouldPublish()
        {
            const string body              = "test_message";
            const string correlationId     = "correlationId";
            var          publisherMock     = new Mock <IPublisher>();
            var          serializerMock    = new Mock <IPublisherSerializer>();
            var          routingMock       = new Mock <IRouting>();
            var          cancellationToken = new CancellationToken();

            publisherMock
            .Setup(x => x.PublishAsync(It.IsAny <PublisherMessage>(), cancellationToken))
            .Verifiable();

            var message = new PublisherMessage(
                publisherMock.Object,
                body,
                serializerMock.Object,
                routingMock.Object,
                correlationId,
                cancellationToken);

            await message.PublishAsync(cancellationToken);

            message.Should().NotBeNull();
            message.GetHeaders().Should().ContainKey("PublishedAt");
            message.GetHeaders()["PublishedAt"].ToString().Should().MatchRegex(@"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}");
            publisherMock.VerifyAll();
        }
        public void GivenMessage_ShouldInstantiate()
        {
            const string body              = "";
            const string correlationId     = "correlationId";
            var          publisherMock     = new Mock <IPublisher>();
            var          serializerMock    = new Mock <IPublisherSerializer>();
            var          routingMock       = new Mock <IRouting>();
            var          cancellationToken = new CancellationToken();

            var message = new PublisherMessage(publisherMock.Object, body, serializerMock.Object, routingMock.Object,
                                               correlationId,
                                               cancellationToken);

            message.Should().NotBeNull();
            message.Routing.Should().Be(routingMock.Object);
            message.CancellationToken.Should().Be(cancellationToken);
            message.CorrelationId.Should().Be(correlationId);
            message.CreatedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(1));
        }
        public void GivenMessage_WhenSerialize_ShouldSerialize()
        {
            const string body              = "test_message";
            const string correlationId     = "correlationId";
            var          resultBody        = Encoding.UTF8.GetBytes(body);
            var          publisherMock     = new Mock <IPublisher>();
            var          serializerMock    = new Mock <IPublisherSerializer>();
            var          routingMock       = new Mock <IRouting>();
            var          cancellationToken = new CancellationToken();

            serializerMock.Setup(x => x.Serialize(body))
            .Returns(resultBody)
            .Verifiable();

            var message = new PublisherMessage(publisherMock.Object, body, serializerMock.Object, routingMock.Object,
                                               correlationId,
                                               cancellationToken);

            var result = message.Serialize();

            message.Should().NotBeNull();
            Encoding.UTF8.GetString(result.ToArray()).Should().Be(body);
            serializerMock.VerifyAll();
        }