protected void ShowTestResults() { TestContext.WriteLine("Test Config"); TestContext.WriteLine(" Connection String: {0}", TestSettings.ConnectionStrings.EventuateTramDbConnection); TestContext.WriteLine(" Kafka server: {0}", TestSettings.KafkaBootstrapServers); TestContext.WriteLine(" Schema: {0}", EventuateDatabaseSchemaName); TestContext.WriteLine(" Dispatcher Id: {0}", _subscriberId); TestContext.WriteLine(" Aggregate Type 12: {0}", AggregateType12); TestContext.WriteLine(" Aggregate Type 34: {0}", AggregateType34); TestContext.WriteLine("Test Results"); TestContext.WriteLine(" N Messages in DB: {0}", _dbContext.Messages.Count()); TestContext.WriteLine(" Unpublished Count: {0}", _dbContext.Messages.Count(msg => msg.Published == 0)); TestContext.WriteLine(" N Received in DB: {0}", _dbContext.ReceivedMessages.Count(msg => msg.MessageId != null)); foreach (Type eventType in _testEventConsumer.GetEventTypes()) { TestContext.WriteLine($" Received {eventType.Name} {_testEventConsumer.GetEventStatistics(eventType).MessageCount}"); } TestContext.WriteLine(" Exception Count: {0}", _testEventConsumer.ExceptionCount); if (_interceptor != null) { TestContext.WriteLine("Message Interceptor Counts"); TestContext.WriteLine(" Pre Send: {0}", _interceptor.PreSendCount); TestContext.WriteLine(" Post Send: {0}", _interceptor.PostSendCount); TestContext.WriteLine(" Pre Receive: {0}", _interceptor.PreReceiveCount); TestContext.WriteLine(" Post Receive: {0}", _interceptor.PostReceiveCount); TestContext.WriteLine(" Pre Handle: {0}", _interceptor.PreHandleCount); TestContext.WriteLine(" Post Handle: {0}", _interceptor.PostHandleCount); } }
public void Publish_MultipleSubscribedMessageTypes_AllMessagesReceived() { // Arrange TestMessageType1 msg1 = new TestMessageType1("Msg1", 1, 1.2); TestMessageType2 msg2 = new TestMessageType2("Msg2", 2); TestMessageType3 msg3 = new TestMessageType3("Msg3", 3); TestMessageType4 msg4 = new TestMessageType4("Msg4", 4); TestEventConsumer consumer = GetTestConsumer(); // Act GetTestPublisher().Publish(AggregateType12, AggregateType12, new List <IDomainEvent> { msg1 }); GetTestPublisher().Publish(AggregateType12, AggregateType12, new List <IDomainEvent> { msg2 }); GetTestPublisher().Publish(AggregateType34, AggregateType34, new List <IDomainEvent> { msg3 }); GetTestPublisher().Publish(AggregateType34, AggregateType34, new List <IDomainEvent> { msg4 }); // Allow time for messages to process int count = 10; while (consumer.TotalMessageCount() < 4 && count > 0) { Thread.Sleep(1000); count--; } ShowTestResults(); // Assert Assert.That(GetDbContext().Messages.Count(), Is.EqualTo(4), "Number of messages produced"); Assert.That(GetDbContext().Messages.Count(msg => msg.Published == 0), Is.EqualTo(0), "Number of unpublished messages"); foreach (Type eventType in consumer.GetEventTypes()) { TestEventConsumer.EventStatistics eventStatistics = consumer.GetEventStatistics(eventType); Assert.That(eventStatistics.MessageCount, Is.EqualTo(1), $"Number of {eventType.Name} messages received by consumer"); Assert.That(eventStatistics.ReceivedMessages.Count, Is.EqualTo(1), $"Number of received {eventType.Name} messages"); } Assert.That(consumer.TotalMessageCount(), Is.EqualTo(4), "Total number of messages received by consumer"); Assert.That(GetDbContext().ReceivedMessages.Count(msg => msg.MessageId != null), Is.EqualTo(4), "Number of received messages"); msg1.AssertGoodMessageReceived(consumer.GetEventStatistics(typeof(TestMessageType1)).ReceivedMessages[0]); msg2.AssertGoodMessageReceived(consumer.GetEventStatistics(typeof(TestMessageType2)).ReceivedMessages[0]); msg3.AssertGoodMessageReceived(consumer.GetEventStatistics(typeof(TestMessageType3)).ReceivedMessages[0]); msg4.AssertGoodMessageReceived(consumer.GetEventStatistics(typeof(TestMessageType4)).ReceivedMessages[0]); GetTestMessageInterceptor()?.AssertCounts(4, 4, 4, 4, 4, 4); }