public async Task HandleIncomingTest()
        {
            var metadata = new MessageMetadata <DummyEvent>(ServiceName, _domainEvent);
            var receiver = new DefaultMessageReceiver(_options.Object, _logger.Object, _services.BuildServiceProvider(), _serializer.Object);

            _serializer.Setup(s => s.DeserializeAsync <MessageMetadata <DummyEvent> >(_serializedDomainEvent, default))
            .Returns(Task.FromResult(metadata));
            _handler.Setup(h => h.HandleAsync(_domainEvent)).Verifiable();

            await receiver.HandleIncoming(typeof(DummyEvent), _serializedDomainEvent);

            _handler.Verify();
        }
        public async Task handleIncomingWaitsForHandlers()
        {
            var receiver    = new DefaultMessageReceiver(_options.Object, _logger.Object, _services.BuildServiceProvider(), _serializer.Object);
            var handlerTask = new TaskCompletionSource <int>();

            _serializer.Setup(s => s.DeserializeAsync <MessageMetadata <DummyEvent> >(_serializedDomainEvent, default))
            .Returns(Task.FromResult(new MessageMetadata <DummyEvent>(ServiceName, _domainEvent)));
            _handler.Setup(h => h.HandleAsync(It.IsAny <DummyEvent>())).Returns(handlerTask.Task);
            var handleIncomingTask = receiver.HandleIncoming(typeof(DummyEvent), _serializedDomainEvent);

            Assert.False(handleIncomingTask.IsCompleted);
            handlerTask.SetResult(1);                         // Simulate completion of the handler.
            await Task.Delay(TimeSpan.FromMilliseconds(100)); // Give HandleIncoming a chance to complete.

            Assert.True(handleIncomingTask.IsCompleted);
        }