public void WhenReceivedEventIsNotNullThenShouldReturnEventContext()
        {
            var serializer    = ServiceProvider.GetRequiredService <IEventSerializer>();
            var factory       = ServiceProvider.GetRequiredService <IEventContextFactory>();
            var @event        = new CreateTestEvent();
            var streamId      = Guid.NewGuid().ToString();
            var causationId   = CausationId.From(Guid.NewGuid().ToString());
            var correlationId = CorrelationId.New();
            var actor         = "test-user";

            var message = new Message
            {
                MessageId      = @event.Id.ToString(),
                Body           = Encoding.UTF8.GetBytes(serializer.Serialize(@event)),
                Label          = nameof(CreateTestEvent),
                CorrelationId  = correlationId.ToString(),
                UserProperties =
                {
                    { nameof(IEventContext <IEvent> .StreamId),    streamId.ToString()    },
                    { nameof(IEventContext <IEvent> .CausationId), causationId.ToString() },
                    { nameof(IEventContext <IEvent> .Actor),       actor                  },
                    { nameof(IEventContext <IEvent> .Timestamp),   @event.Timestamp       },
                },
            };

            var context = factory.CreateContext(message);

            context.StreamId.Should().Be(streamId);
            context.CausationId.Should().Be(causationId);
            context.CorrelationId.Should().Be(correlationId);
            context.Payload.Should().BeOfType <CreateTestEvent>();
            context.Timestamp.Should().Be(@event.Timestamp);
            context.Actor.Should().Be(Actor.From(actor));
        }
        public void WhenReceivedEventIsNotNullThenShouldReturnEventContext()
        {
            var serializer    = ServiceProvider.GetRequiredService <IEventSerializer>();
            var factory       = ServiceProvider.GetRequiredService <IEventContextFactory>();
            var properties    = Mock.Of <MQ.Impl.BasicProperties>();
            var @event        = new CreateTestEvent();
            var causationId   = CausationId.From(Guid.NewGuid().ToString());
            var correlationId = CorrelationId.New();
            var actor         = "test-user";

            properties.Headers = new Dictionary <string, object>
            {
                { nameof(IEventContext <IEvent> .CausationId), causationId },
                { nameof(IEventContext <IEvent> .CorrelationId), correlationId },
                { nameof(IEventContext <IEvent> .Actor), actor },
            };

            var message = new ReceivedMessage(new BasicDeliverEventArgs
            {
                RoutingKey      = nameof(CreateTestEvent),
                Body            = Encoding.UTF8.GetBytes(serializer.Serialize(@event)),
                BasicProperties = properties,
            });
            var context = factory.CreateContext(message);

            context.CausationId.Should().Be(causationId);
            context.CorrelationId.Should().Be(correlationId);
            context.Payload.Should().BeOfType <CreateTestEvent>();
            context.Timestamp.Should().Be(@event.Timestamp);
            context.Actor.Should().Be(Actor.From(actor));
        }