コード例 #1
0
        public void StartListeningShouldThrowExceptionWhenAlreadyListening()
        {
            // Arrange
            Mock <TestBusContext> context = new Mock <TestBusContext>();

            string[] topics = new string[0];
            string   queue  = "queue.name";

            var receiver = new TestMessageReceiver(context.Object, queue, topics);

            receiver.StartReceivingMessages();

            // Act
            void Act() => receiver.StartReceivingMessages();

            // Assert
            var exception = Assert.ThrowsException <BusConfigurationException>(Act);

            Assert.AreEqual("Receiver is already listening to events!", exception.Message);
        }
コード例 #2
0
        public void PausePausesReceiver()
        {
            // Arrange
            Mock <TestBusContext> context = new Mock <TestBusContext>(MockBehavior.Strict);
            var receiver = new TestMessageReceiver(context.Object, "queue", new string[0]);

            receiver.StartReceivingMessages();

            // Act
            receiver.Pause();

            // Assert
            Assert.IsTrue(receiver.IsPaused);
        }
コード例 #3
0
        public void ResumeThrowsExceptionIfNotPaused()
        {
            // Arrange
            Mock <TestBusContext> context = new Mock <TestBusContext>(MockBehavior.Strict);
            var receiver = new TestMessageReceiver(context.Object, "queue", new string[0]);

            receiver.StartReceivingMessages();

            // Act
            void Act() => receiver.Resume();

            // Assert
            BusConfigurationException exception = Assert.ThrowsException <BusConfigurationException>(Act);

            Assert.AreEqual("Attempting to resume the TestMessageReceiver, but it was not paused.", exception.Message);
        }
コード例 #4
0
        public void StartReceivingCreatesQueueWrapperInDictionary(string queue, string topics)
        {
            // Arrange
            Mock <TestBusContext> context = new Mock <TestBusContext>(MockBehavior.Strict);
            var dictionary = new Dictionary <TestBusKey, TestBusQueueWrapper <EventMessage> >();

            context.SetupGet(e => e.DataQueues)
            .Returns(dictionary);

            string[] topicNames = topics.Split(',');

            var receiver = new TestMessageReceiver(context.Object, queue, topicNames);

            // Act
            receiver.StartReceivingMessages();

            // Assert
            foreach (var topic in topicNames)
            {
                var key = new TestBusKey(queue, topic);
                Assert.IsTrue(dictionary.ContainsKey(key));
            }
        }