Class to publish messages to the bus
Inheritance: IMessagePublisher
        public void PublishAddsMessageToBus()
        {
            var bus = new Mock<IAdvancedBus>();
            var logger = new Mock<ILogger>();
            var queue = new Mock<IQueue>();
            var exchange = new Mock<IExchange>();

            var messagePublisher = new MessagePublisher(bus.Object, logger.Object,exchange.Object,queue.Object);

            messagePublisher.Publish(TestMessages.GetTestReadSampleEntityMessage(), "A.B");

            bus.Verify(o => o.Publish<object>(It.IsAny<IExchange>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<IMessage<object>>()), Times.Once());
        }
        public void PublishLogsMessageIsPublished()
        {
            var bus = new Mock<IAdvancedBus>();
            var logger = new Mock<ILogger>();
            var queue = new Mock<IQueue>();
            var exchange = new Mock<IExchange>();

            var messagePublisher = new MessagePublisher(bus.Object, logger.Object, exchange.Object, queue.Object);
            var invocations = new List<string>();
            logger.Setup(loggerObj => loggerObj.Info(It.IsAny<string>()))
                .Callback<string, Object[]>((message, obj) => invocations.Add(message));

            messagePublisher.Publish(TestMessages.GetTestReadSampleEntityMessage(), "A.B");

            Assert.IsTrue(invocations[1].Contains("Publish Message succeded"));
        }
        public void PublishFailiureLogsErrorMessage()
        {
            var bus = new Mock<IAdvancedBus>();
            var logger = new Mock<ILogger>();
            var queue = new Mock<IQueue>();
            var exchange = new Mock<IExchange>();

            var messagePublisher = new MessagePublisher(bus.Object, logger.Object, exchange.Object, queue.Object);
            var invocations = new List<string>();
            logger.Setup(loggerObj => loggerObj.Error(It.IsAny<string>(), It.IsAny<object[]>()))
                .Callback<string, object[]>((message, obj) => invocations.Add(message));
            bus.Setup(busObj => busObj.Publish<object>(It.IsAny<IExchange>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<IMessage<object>>()))
                .Throws(new EasyNetQException("Test error"));

            messagePublisher.Publish(TestMessages.GetTestReadSampleEntityMessage(), "A.B");

            Assert.IsTrue(invocations[0].Contains("Publish Message Failed: "));
        }
        public void ServicePublishesMessages()
        {
            var logger = new Mock<ILogger>();
            var repo = new Mock<IRepository<SampleEntity>>();
            var env = new Mock<IEnvironment>();
            var bus = BusFactory.CreateMessageBus();
            var queue = QueueFactory.CreatQueue(bus);
            var exchange = ExchangeFactory.CreatExchange(bus);
            bus.Bind(exchange, queue, "A.*");
            var publisher = new MessagePublisher(bus, logger.Object, exchange,queue);

            var dataOps = new DataOperations(logger.Object, publisher,repo.Object,env.Object);
            var filter = new MessageFilter(env.Object, logger.Object);
            var logicClass = new MessageRouter(logger.Object, dataOps, filter);
            var messageData = TestMessages.GetTestCreateSampleEntityMessage();
            env.Setup(e => e.GetServiceName()).Returns("Fake-Service");
            env.Setup(e => e.GetServiceVersion()).Returns(2);

            var newEntities = new List<SampleEntity>();
            var entity = new SampleEntity
            {
                UpdatedDate = DateTime.UtcNow,
                CreatedDate = DateTime.UtcNow,
                Id = Guid.NewGuid().ToString(),
                NewDecimalValue = 1.02M,
                NewGuidValue = Guid.NewGuid(),
                NewIntValue = 3,
                NewStringValue = "test"
            };
            newEntities.Add(entity);
            var recivedMessages = new List<dynamic>();

            var consumer = bus.Consume<object>(queue, (message, info) =>
                 Task.Factory.StartNew(() =>
                      recivedMessages.Add(message)
                     )
                 );

            logicClass.RouteSampleMessage(messageData);
            System.Threading.Thread.Sleep(5000);

            consumer.Dispose();
            Assert.IsTrue(recivedMessages.Count >= 1);
        }