public void Execute(int logFileId, string filePath) { LogFileModel logFile = _logFileRepo.GetById(logFileId); try { // load the contents of the file List <W3CEvent> logEvents; try { logEvents = W3CEnumerable.FromFile(filePath).ToList(); } catch (Exception) { throw new FileFormatException("File is not a valid IIS log file"); } // save the requests _createRequestBatchCommand.Execute(logFileId, logEvents); // update the record count of the log file const string sql = "UPDATE LogFiles SET RecordCount = @RecordCount WHERE Id = @Id"; _dbContext.ExecuteNonQuery(sql, new { Id = logFileId, RecordCount = logEvents.Count }); // delete the file _fileWrap.Delete(filePath); // register the job that marks the file as needing aggregate processing _jobRegistrationService.RegisterResetProcessedLogFileJob(logFile.Id); } catch (Exception ex) { // try and update the status of the log file record, the file will be marked as in an error state logFile.Status = BLL.Lookup.LogFileStatus.Error; logFile.ErrorMsg = ex.Message; string sql = "UPDATE LogFiles SET Status = @Status, ErrorMsg = @ErrorMsg WHERE Id = @Id"; _dbContext.ExecuteNonQuery(sql, logFile); } }
public void Execute_ValidationSucceeds_BatchInserted() { int logFileId = new Random().Next(1, 1000); _requestValidator.Validate(Arg.Any <RequestModel>()).Returns(new ValidationResult()); using (StreamReader logStream = new StreamReader(TestAsset.ReadTextStream(TestAsset.LogFile))) { var logEvents = W3CEnumerable.FromStream(logStream).ToList(); int eventCount = logEvents.Count; Assert.Greater(eventCount, 1); // execute _createRequestBatchCommand.Execute(logFileId, logEvents); // assert _requestValidator.Received(eventCount).Validate(Arg.Any <RequestModel>()); // should receive eventCount + 1 -> delete also done _dbContext.Received(eventCount + 1).ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>()); } }