public void PostOperationCallsCreateDataOperation() { var env = new Mock<IEnvironment>(); var dataOps = new Mock<IDataOperations>(); var logger = new Mock<ILogger>(); var filter = new MessageFilter(env.Object, logger.Object); var logicClass = new MessageRouter(logger.Object, dataOps.Object, filter); var message = TestMessages.GetTestCreateSampleEntityMessage(); logicClass.RouteSampleMessage(message); dataOps.Verify(d => d.CreateSampleEntities(It.IsAny<object>()), Times.Once()); }
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); }