Esempio n. 1
0
        public void When_first_batch_available_to_process()
        {
            var batchId = Guid.NewGuid();
            var jobs    = new List <Job>
            {
                new Job
                {
                    Id     = Guid.NewGuid(),
                    Data   = "ABC",
                    Status = ProcessStatus.Created
                }
            };

            _dbContext.Batches.Add(new Batch
            {
                CreatedOn = DateTime.Now,
                Id        = batchId,
                Jobs      = jobs,
                Status    = ProcessStatus.Created
            });
            var runner = new BatchingLibrary.BatchRunner.BatchRunner(_dbContext, _batchRunnerService);

            runner.SendBatchToProcessor();

            _processorMock.Verify(p => p.Process(It.IsAny <Batch>()), Times.AtMostOnce);

            Assert.NotNull(_dbContext.ProcessorLastExecution.LastRun);
            Assert.Equal(batchId, _dbContext.ProcessorLastExecution.BatchId);
        }
Esempio n. 2
0
        public void When_no_batch_available_to_process_and_no_previous_executions_happened()
        {
            var runner = new BatchingLibrary.BatchRunner.BatchRunner(_dbContext, _batchRunnerService);

            runner.SendBatchToProcessor();

            _processorMock.Verify(p => p.Process(It.IsAny <Batch>()), Times.Never());
            Assert.Null(_dbContext.ProcessorLastExecution.LastRun);
            Assert.Null(_dbContext.ProcessorLastExecution.BatchId);
        }
Esempio n. 3
0
        public void Should_not_process_any_batch_if_processor_latency_not_met()
        {
            var lastBatch = Guid.NewGuid();

            _dbContext.BatchConfiguration.LatencyInSeconds = 10;
            _dbContext.ProcessorLastExecution.LastRun      = DateTime.Now.AddSeconds(6);
            _dbContext.ProcessorLastExecution.BatchId      = lastBatch;

            var batchId = Guid.NewGuid();
            var jobs    = new List <Job>
            {
                new Job
                {
                    Id     = Guid.NewGuid(),
                    Data   = "ABC",
                    Status = ProcessStatus.Created
                }
            };

            _dbContext.Batches.Add(new Batch
            {
                CreatedOn = DateTime.Now,
                Id        = batchId,
                Jobs      = jobs,
                Status    = ProcessStatus.Created
            });


            var runner = new BatchingLibrary.BatchRunner.BatchRunner(_dbContext, _batchRunnerService);

            runner.SendBatchToProcessor();

            _processorMock.Verify(p => p.Process(It.IsAny <Batch>()), Times.Never);

            Assert.Equal(lastBatch, _dbContext.ProcessorLastExecution.BatchId);
        }