예제 #1
0
        public void Execute_ValidLogFile_ProcessesFileAndRegistersJob()
        {
            LogFileModel logFile = DataHelper.CreateLogFileModel();

            string fileName = Path.GetRandomFileName() + ".log";
            string filePath = Path.Combine(AppContext.BaseDirectory, fileName);

            // save the text file
            using (Stream stream = TestAsset.ReadTextStream(TestAsset.LogFile))
            {
                var fileStream = File.Create(filePath);
                stream.Seek(0, SeekOrigin.Begin);
                stream.CopyTo(fileStream);
                fileStream.Close();
            }


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

            // execute
            _processLogFileCommand.Execute(logFile.Id, filePath);

            // assert
            _createRequestBatchCommand.Received(1).Execute(logFile.Id, Arg.Any <IEnumerable <W3CEvent> >());
            _dbContext.Received(1).ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
            _jobRegistrationService.Received(1).RegisterResetProcessedLogFileJob(logFile.Id);
            _fileWrap.Received(1).Delete(filePath);
        }
예제 #2
0
        public void Execute_ValidationSucceeds_RecordInsertedAndJobRegistered()
        {
            int        projectId  = new Random().Next(1, 1000);
            string     filePath   = Path.Combine(AppContext.BaseDirectory, "test.log");
            FileDetail fileDetail = new FileDetail();

            fileDetail.Length = new Random().Next(1000, 10000);
            fileDetail.Hash   = Guid.NewGuid().ToString();
            fileDetail.Name   = Guid.NewGuid().ToString();

            _fileUtils.GetFileHash(filePath).Returns(fileDetail);

            _logFileValidator.Validate(Arg.Any <LogFileModel>()).Returns(new ValidationResult());

            // execute
            LogFileModel result = _createLogFileCommand.Execute(projectId, filePath);

            // assert
            _dbContext.Received(1).ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
            _dbContext.Received(1).ExecuteScalar <int>(Arg.Any <string>());
            _jobRegistrationService.Received(1).RegisterProcessLogFileJob(result.Id, filePath);

            Assert.AreEqual(projectId, result.ProjectId);
            Assert.AreEqual(fileDetail.Hash, result.FileHash);
            Assert.AreEqual(fileDetail.Length, result.FileLength);
            Assert.AreEqual(fileDetail.Name, result.FileName);
            Assert.AreEqual(-1, result.RecordCount);
            Assert.AreEqual(LogFileStatus.Processing, result.Status);
        }
        public void Execute_OnExecution_RunsQueriesAndRegistersJob()
        {
            int logFileId = new Random().Next(100, 1000);

            // execute
            _setLogFileUnprocessedCommand.Execute(logFileId);

            // assert
            _dbContext.Received(1).ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
            _jobRegistrationService.Received(1).RegisterAggregateRequestJob(logFileId);
        }