public void PublishEventsToCertainQueueTestFourTimes() { var repoMock = new Mock <IRepository>(MockBehavior.Strict); var ev = new SerializedEvent() { ID = 1337, TimeReceived = DateTime.Now, Body = "test body", EventType = typeof(TestEvent).FullName, RoutingKey = "#" }; repoMock.Setup(repo => repo.FindBy(It.IsAny <Expression <Func <SerializedEvent, bool> > >())).Returns(() => new List <SerializedEvent>() { ev, ev, ev, ev }); var queueName = "TestQueue2"; using (var sender = new EventPublisher(_busOptions)) using (var receiver = new TestDispatcher(_direct, queueName)) using (var publisher = new AuditPublisher(_direct)) using (var dispatcher = new AuditDispatcher(repoMock.Object, publisher, _busOptions)) { var saec = new SendAllEventCommand(); saec.returnQueueName = queueName; saec.StartTime = DateTime.MinValue; saec.EndTime = DateTime.MaxValue; sender.Publish(saec); Thread.Sleep(1000); Assert.AreEqual(4, receiver.ReceivedTestEventCount); } }
public void OnReceived(SendAllEventCommand command) { var results = _repository.FindBy(s => s.TimeReceived >= command.StartTime && s.TimeReceived <= command.EndTime && isRoutingKeyMatch(command.RoutingKey, s.RoutingKey) ); var orderedResult = results.OrderBy(s => s.TimeReceived); foreach (var serializedEvent in orderedResult) { _publisher.Publish(command.returnQueueName, serializedEvent); } }
public void AuditDispatcherCallsCorrectMethodsCount() { // Arrange var repoMock = new Mock <IRepository>(MockBehavior.Strict); repoMock.Setup(repo => repo.Insert(It.IsAny <SerializedEvent>())); var e = new SerializedEvent { Body = "AuditDispatcher.Test", TimeReceived = DateTime.Now }; repoMock.Setup(repo => repo.FindBy(It.IsAny <Expression <Func <SerializedEvent, bool> > >())) .Returns(() => new List <SerializedEvent>() { e, e, e }); var pubMock = new Mock <IPublisher>(MockBehavior.Strict); pubMock.Setup(pub => pub.Publish(It.IsAny <string>(), It.IsAny <SerializedEvent>())); options.ExchangeName = "TestExchange2"; using (var target = new AuditDispatcher(repoMock.Object, pubMock.Object, options)) { // Act var command = new SendAllEventCommand { returnQueueName = "Test.QueueName", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue }; target.OnReceived(command); // Assert repoMock.Verify(repo => repo.FindBy(It.IsAny <Expression <Func <SerializedEvent, bool> > >()), Times.Once()); pubMock.Verify(pub => pub.Publish(It.IsAny <string>(), It.IsAny <SerializedEvent>()), Times.Exactly(3)); } }