Esempio n. 1
0
        public void WorkerLoopWhenQueueContainsMessage()
        {
            // arrange
            var connection = new Mock <IConnection>();
            var worker     = new MessageSender(connection.Object);
            var message    = new SerializedMessage("TestRoute", new byte[] { 1, 2, 3 });

            // act
            worker.SendMessage(message);
            var firstProcessing  = worker.DoWork();
            var secondProcessing = worker.DoWork();

            // assert
            Assert.IsTrue(firstProcessing);
            Assert.IsFalse(secondProcessing);

            connection.Verify(x => x.SendMessage(message), Times.Once);
        }
Esempio n. 2
0
        public void WorkerLoopWhenQueueIsEmpty()
        {
            // arrange
            var connection = new Mock <IConnection>();
            var worker     = new MessageSender(connection.Object);

            // act
            var messageProcessed = worker.DoWork();

            // assert
            Assert.IsFalse(messageProcessed);

            connection.Verify(x => x.SendMessage(It.IsAny <SerializedMessage>()), Times.Never);
        }
Esempio n. 3
0
        public void OnException()
        {
            // arrange
            var connection = new Mock <IConnection>();

            connection.Setup(x => x.SendMessage(It.IsAny <SerializedMessage>())).Throws <Exception>();

            var worker  = new MessageSender(connection.Object);
            var message = new SerializedMessage("TestRoute", new byte[] { 1, 2, 3 });

            // act
            worker.SendMessage(message);

            // assert
            Assert.Throws <ConnectionException>(() =>
            {
                worker.DoWork();
            });
        }