Example #1
0
        public void Execute_AggregatesSameAsUriStem_RequestNotUpdated()
        {
            int logFileId = new Random().Next(1, 1000);

            // setup
            RequestModel requestModel = DataHelper.CreateRequestModel(logFileId);

            requestModel.UriStem = "TEST";

            RequestModel[] requests = { requestModel };
            _requestRepo.GetByLogFile(logFileId).Returns(requests);

            LogFileModel logFile = DataHelper.CreateLogFileModel();

            logFile.Id = logFileId;
            _logFileRepo.GetById(logFileId).Returns(logFile);

            _requestAggregationService.GetAggregatedUriStem(Arg.Any <string>(), Arg.Any <IEnumerable <ProjectRequestAggregateModel> >()).Returns(requestModel.UriStem);

            // execute
            _resetRequestAggregateCommand.Execute(logFileId);

            // assert
            _requestAggregationService.Received(1).GetAggregatedUriStem(Arg.Any <string>(), Arg.Any <IEnumerable <ProjectRequestAggregateModel> >());
            _dbContext.Received(2).ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
        }
        public void GetAggregatedUriStem_SuppliedAggregatesNull_ReturnsOriginal()
        {
            string uriStem = Path.GetRandomFileName();

            string result = _requestAggregationService.GetAggregatedUriStem(uriStem, null);

            Assert.AreEqual(uriStem, result);
        }
        public void Execute(int logFileId)
        {
            // load all the requests for the log file
            IEnumerable <RequestModel> requests = _requestRepo.GetByLogFile(logFileId);

            // only apply aggregates if we have requests!
            if (requests.Any())
            {
                // load all the aggregates for the project
                LogFileModel logFile = _logFileRepo.GetById(logFileId);
                IEnumerable <ProjectRequestAggregateModel> requestAggregates = _projectRequestAggregateRepo.GetByProject(logFile.ProjectId);

                // run through the requests and apply the configured aggregates - if the value changes then update in the database
                foreach (var req in requests)
                {
                    const string usql             = "UPDATE Requests SET UriStemAggregate = @UriStemAggregate WHERE Id = @RequestId";
                    string       uriStemAggregate = _requestAggregationService.GetAggregatedUriStem(req.UriStem, requestAggregates);
                    if (uriStemAggregate != req.UriStemAggregate)
                    {
                        _dbContext.ExecuteNonQuery(usql, new { UriStemAggregate = uriStemAggregate, RequestId = req.Id });
                    }
                }
            }

            // mark the log file as processed
            string sql = "UPDATE LogFiles SET Status = @Status WHERE Id = @LogFileId";

            _dbContext.ExecuteNonQuery(sql, new { LogFileId = logFileId, Status = LogFileStatus.Complete });
            _logger.Info("Marked LogFile {0} as Complete", logFileId);
        }