public void TimerShouldRemoveAllProcessedMessagesFromPersistor()
        {
            // Arrange
            var mockPersistor = new Mock <IAggregatorPersistor>();
            var mockContainer = new Mock <IBusContainer>();
            var mockLogger    = new Mock <ILogger>();

            var timer = new AggregatorProcessor(mockPersistor.Object, mockContainer.Object, typeof(FakeAggregator), mockLogger.Object);

            mockPersistor.Setup(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(1);
            var aggregator = new FakeAggregator();
            var message    = new FakeMessage1(Guid.NewGuid());

            mockContainer.Setup(x => x.GetInstance(typeof(FakeAggregator))).Returns(aggregator);
            mockPersistor.Setup(x => x.GetData(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(new List <object> {
                message
            });

            // Act
            timer.StartTimer <FakeMessage1>(new TimeSpan(0, 0, 0, 0, 50));
            Thread.Sleep(100);

            // Assert
            mockPersistor.Verify(x => x.RemoveData(typeof(FakeMessage1).AssemblyQualifiedName, message.CorrelationId), Times.Once);

            timer.Dispose();
        }
        public void TimerShouldGetMessagesFromAggregatorAndExecuteHandler()
        {
            // Arrange
            var mockPersistor = new Mock <IAggregatorPersistor>();
            var mockContainer = new Mock <IBusContainer>();
            var mockLogger    = new Mock <ILogger>();

            var timer = new AggregatorProcessor(mockPersistor.Object, mockContainer.Object, typeof(FakeAggregator), mockLogger.Object);

            mockPersistor.Setup(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(1);
            var aggregator = new FakeAggregator();
            var message    = new FakeMessage1(Guid.NewGuid());

            mockContainer.Setup(x => x.GetInstance(typeof(FakeAggregator))).Returns(aggregator);
            mockPersistor.Setup(x => x.GetData(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(new List <object> {
                message
            });

            // Act
            timer.StartTimer <FakeMessage1>(new TimeSpan(0, 0, 0, 0, 50));
            Thread.Sleep(90);

            // Assert
            mockPersistor.Verify(x => x.GetData(typeof(FakeMessage1).AssemblyQualifiedName), Times.Once);
            Assert.Equal(1, aggregator.Messages.Count);
            Assert.Equal(message, aggregator.Messages.First());
            timer.Dispose();
        }
        public void TimerShouldRunEverySecond()
        {
            // Arrange
            var mockPersistor = new Mock<IAggregatorPersistor>();
            var mockContainer = new Mock<IBusContainer>();

            var timer = new AggregatorProcessor(mockPersistor.Object, mockContainer.Object, typeof (FakeAggregator));

            var count = 0;

            mockPersistor.Setup(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(0).Callback(() => count++);

            // Act
            timer.StartTimer<FakeMessage1>(new TimeSpan(0, 0, 0, 1));
            Thread.Sleep(2100);

            // Assert 
            mockPersistor.Verify(x => x.Count(typeof (FakeMessage1).AssemblyQualifiedName), Times.Exactly(2));
            Assert.Equal(2, count);

            timer.Dispose();
        }
Exemple #4
0
        public void TimerShouldRunEverySecond()
        {
            // Arrange
            var mockPersistor = new Mock <IAggregatorPersistor>();
            var mockContainer = new Mock <IBusContainer>();

            var timer = new AggregatorProcessor(mockPersistor.Object, mockContainer.Object, typeof(FakeAggregator));

            var count = 0;

            mockPersistor.Setup(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(0).Callback(() => count++);

            // Act
            timer.StartTimer <FakeMessage1>(new TimeSpan(0, 0, 0, 1));
            Thread.Sleep(2100);

            // Assert
            mockPersistor.Verify(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName), Times.Exactly(2));
            Assert.Equal(2, count);

            timer.Dispose();
        }
        public void TimerShouldReset()
        {
            // Arrange
            var mockPersistor = new Mock <IAggregatorPersistor>();
            var mockContainer = new Mock <IBusContainer>();
            var mockLogger    = new Mock <ILogger>();

            var timer = new AggregatorProcessor(mockPersistor.Object, mockContainer.Object, typeof(FakeAggregator), mockLogger.Object);

            var count = 0;

            mockPersistor.Setup(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(0).Callback(() => count++);

            // Act
            timer.StartTimer <FakeMessage1>(new TimeSpan(0, 0, 0, 2));
            Thread.Sleep(1100);
            timer.ResetTimer();
            Thread.Sleep(1000);
            timer.Dispose();

            // Assert
            Assert.Equal(0, count);
        }
        public void TimerShouldGetMessagesFromAggregatorAndExecuteHandler()
        {
            // Arrange
            var mockPersistor = new Mock<IAggregatorPersistor>();
            var mockContainer = new Mock<IBusContainer>();

            var timer = new AggregatorProcessor(mockPersistor.Object, mockContainer.Object, typeof(FakeAggregator));

            mockPersistor.Setup(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(1);
            var aggregator = new FakeAggregator();
            var message = new FakeMessage1(Guid.NewGuid());
            mockContainer.Setup(x => x.GetInstance(typeof (FakeAggregator))).Returns(aggregator);
            mockPersistor.Setup(x => x.GetData(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(new List<object>{ message });

            // Act
            timer.StartTimer<FakeMessage1>(new TimeSpan(0, 0, 0, 0, 50));
            Thread.Sleep(90);

            // Assert 
            mockPersistor.Verify(x => x.GetData(typeof(FakeMessage1).AssemblyQualifiedName), Times.Once);
            Assert.Equal(1, aggregator.Messages.Count);
            Assert.Equal(message, aggregator.Messages.First());
            timer.Dispose();
        }
        public void TimerShouldRemoveAllProcessedMessagesFromPersistor()
        {
            // Arrange
            var mockPersistor = new Mock<IAggregatorPersistor>();
            var mockContainer = new Mock<IBusContainer>();

            var timer = new AggregatorProcessor(mockPersistor.Object, mockContainer.Object, typeof(FakeAggregator));

            mockPersistor.Setup(x => x.Count(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(1);
            var aggregator = new FakeAggregator();
            var message = new FakeMessage1(Guid.NewGuid());
            mockContainer.Setup(x => x.GetInstance(typeof(FakeAggregator))).Returns(aggregator);
            mockPersistor.Setup(x => x.GetData(typeof(FakeMessage1).AssemblyQualifiedName)).Returns(new List<object> { message });

            // Act
            timer.StartTimer<FakeMessage1>(new TimeSpan(0, 0, 0, 0, 50));
            Thread.Sleep(100);

            // Assert 
            mockPersistor.Verify(x => x.RemoveData(typeof(FakeMessage1).AssemblyQualifiedName, message.CorrelationId), Times.Once);
           
            timer.Dispose();
        }