Beispiel #1
0
        public void Execute_FileWithHashAlreadyExists_ThrowsException()
        {
            int        projectId  = new Random().Next(1, 1000);
            string     filePath   = Path.Combine(AppContext.BaseDirectory, "test.log");
            FileDetail fileDetail = new FileDetail();

            fileDetail.Hash = Guid.NewGuid().ToString();

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

            LogFileModel model = DataHelper.CreateLogFileModel();

            _logFileRepo.GetByHash(projectId, fileDetail.Hash).Returns(model);

            // execute
            TestDelegate del = () => _createLogFileCommand.Execute(projectId, filePath);

            // assert
            Assert.Throws <ValidationException>(del);

            _fileUtils.Received(1).GetFileHash(filePath);
            _logFileRepo.Received(1).GetByHash(projectId, fileDetail.Hash);

            // we shouldn't have even tried to validate or do the insert
            _logFileValidator.DidNotReceive().Validate(Arg.Any <LogFileModel>());
            _dbContext.DidNotReceive().ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
        }