public void GivenConnectionWhenSubscribeShouldExecuteCallback() { var exchange = Exchange.Create("seedwork-cqrs-bus.integration-tests", ExchangeType.Direct); var queue = Queue.Create($"seedwork-cqrs-bus.integration-tests.queue-{Guid.NewGuid()}") .WithAutoDelete(); var routingKey = RoutingKey.Create(queue.Name.Value); const string notification = "Notification message"; _connectionFixture.Connection.Publish(exchange, queue, routingKey, notification); IServiceScope callbackScope = null; string callbackMessage = null; var autoResetEvent = new AutoResetEvent(false); _connectionFixture.Connection.Subscribe <string>(exchange, queue, routingKey, 1, (scope, message) => { callbackScope = scope; callbackMessage = message; autoResetEvent.Set(); return(Task.CompletedTask); }); autoResetEvent.WaitOne(); callbackScope.Should().NotBeNull(); callbackMessage.Should().Be(notification); }