public void ProgTypeValidationFail(string progType, string message, string errorCode) { _validModel.CsvRecord.ProgType = progType; var result = _validator.Validate(_validModel); result.IsValid.Should().BeFalse(); result.Errors[0].ErrorMessage.Should().Be(message); result.Errors[0].ErrorCode.Should().Be(errorCode); }
public IEnumerable <UploadError> ValidateRecords(IEnumerable <ApprenticeshipUploadModel> records, List <TrainingProgramme> trainingProgrammes) { var errors = new ConcurrentBag <UploadError>(); var apprenticeshipUploadModels = records as ApprenticeshipUploadModel[] ?? records.ToArray(); Parallel.ForEach(apprenticeshipUploadModels, (record, state, index) => { var viewModel = record.ApprenticeshipViewModel; int i = (int)index + 1; // Validate view model for approval var validationResult = _viewModelValidator.Validate(record); validationResult.Errors.ForEach(m => errors.Add(new UploadError(m.ErrorMessage, m.ErrorCode, i, record))); var validationMessage = ValidateTrainingInConjunctionWithStartDate(viewModel, trainingProgrammes); if (validationMessage != null) { errors.Add(new UploadError(validationMessage.Value.Text, validationMessage.Value.ErrorCode, i, record)); } }); return(errors); }