コード例 #1
0
        public void StringEventListenerReceivesProperString(string text)
        {
            // Arrange
            var testContext = new TestBusContext();
            var hostBuilder = new MicroserviceHostBuilder().WithBusContext(testContext);

            using var host = hostBuilder
                             .WithQueueName("test.queue")
                             .AddEventListener <StringEventListenerDummy>()
                             .CreateHost();

            host.Start();

            //Act
            var message = new DummyEvent("test.topic")
            {
                DummyText = text
            };

            new EventPublisher(testContext).Publish(message);

            // Assert
            Thread.Sleep(WaitTime);

            var expectedResult = JsonConvert.SerializeObject(message);

            Assert.AreEqual(expectedResult, StringEventListenerDummy.ReceivedData);
        }
コード例 #2
0
        public void EventMessageHandledIsFiredOnIncomingMessageWithProperValues()
        {
            // Arrange
            const string queueName       = "test.queue";
            const string topicExpression = "TestTopic";

            var testContext = new TestBusContext();
            var hostBuilder = new MicroserviceHostBuilder()
                              .WithBusContext(testContext)
                              .AddEventListener <EventListenerDummy>()
                              .WithQueueName(queueName);

            using var host = hostBuilder.CreateHost();

            host.Start();

            EventMessage receivedEventMessage = null;
            EventMessageHandledEventArgs receivedEventArgs = null;

            host.EventMessageHandled += (eventMessage, args) =>
            {
                receivedEventMessage = eventMessage;
                receivedEventArgs    = args;
            };

            // Act
            var message = new DummyEvent(topicExpression);

            new EventPublisher(testContext).Publish(message);

            Thread.Sleep(WaitTime);

            // Assert
            Assert.AreEqual(message.Type, receivedEventMessage.EventType);
            Assert.AreEqual(message.Id, receivedEventMessage.CorrelationId);
            Assert.AreEqual(message.Timestamp, receivedEventMessage.Timestamp);

            Assert.AreEqual(queueName, receivedEventArgs.QueueName);
            Assert.AreEqual(1, receivedEventArgs.TopicExpressions.Count());
            Assert.AreEqual(topicExpression, receivedEventArgs.TopicExpressions.Single());
        }
コード例 #3
0
        public void AddingListenerRegistersProperReceiver()
        {
            // Arrange
            var testContext = new TestBusContext();
            var hostBuilder = new MicroserviceHostBuilder().WithBusContext(testContext);

            // Act
            hostBuilder.AddEventListener <EventListenerDummy>();
            hostBuilder.WithQueueName("test.queue");

            hostBuilder.CreateHost().Start();

            // Assert
            var message = new DummyEvent("TestTopic");

            new EventPublisher(testContext).Publish(message);

            Thread.Sleep(WaitTime);

            Assert.AreEqual(message, EventListenerDummy.HandlesResult);
        }
コード例 #4
0
 private bool Equals(DummyEvent other) =>
 DummyText == other.DummyText &&
 Timestamp == other.Timestamp &&
 Id == other.Id &&
 Topic == other.Topic;