public async void InvokeAsync_CorrectSerializedMessageIsProvided_NewConsumerInstanceIsCreatedAndUseed() { //prepare var mockConsumer1 = new Mock <IConsumer <BookingCreated> >(); var mockConsumer2 = new Mock <IConsumer <BookingCreated> >(); int count = 0; Func <IConsumer <BookingCreated> > consumerFactory = () => { if (count == 0) { count = count + 1; return(mockConsumer1.Object); } else { return(mockConsumer2.Object); } }; ISubscription subscription = new Subscription <BookingCreated>(consumerFactory, null); IntegrationEvent <BookingCreated> integrationEvent = new IntegrationEvent <BookingCreated>(new BookingCreated { BookingName = "bookingName" }, "bookingcreatedeventtype"); string serializedMessage = JsonConvert.SerializeObject(integrationEvent); //act await subscription.InvokeAsync(serializedMessage); await subscription.InvokeAsync(serializedMessage); //check var expected = integrationEvent.AsSource().OfLikeness <IntegrationEvent <BookingCreated> >() .With(a => a.Content) .EqualsWhen((p, m) => { return(m.Content.BookingName == p.Content.BookingName); }).CreateProxy(); mockConsumer1.Verify(x => x.ConsumeAsync(expected), Times.Once); mockConsumer2.Verify(x => x.ConsumeAsync(expected), Times.Once); }