public ActionResult Index(MRZDataCaptureModel mrzDataCaptureModel) { string dateOfBirthYYMMDD = string.Empty; string dateOfExpiryYYMMDD = string.Empty; // addition validation to standard model validation // validate dates are valid if (!IsDateValid(mrzDataCaptureModel.DateOfBirth, out dateOfBirthYYMMDD)) { ModelState.AddModelError("DateOfBirth", "Error in date"); } if (!IsDateValid(mrzDataCaptureModel.DateOfExpiry, out dateOfExpiryYYMMDD)) { ModelState.AddModelError("DateOfExpiry", "Error in date"); } if (ModelState.IsValid) { var res = validate.ValidateMRZ(mrzDataCaptureModel.MRZ, mrzDataCaptureModel.PassportNumber, mrzDataCaptureModel.Nationality, dateOfBirthYYMMDD, mrzDataCaptureModel.Gender, dateOfExpiryYYMMDD, mrzDataCaptureModel.PersonalNumber); ValidateMRZResultModel validateMRZResultModel = new ValidateMRZResultModel(); validateMRZResultModel.IsPersonalNumberCheckDigitValid = res.IsPersonalNumberCheckDigitValid; validateMRZResultModel.IsDateOfBirthCheckDigitValid = res.IsDateOfBirthCheckDigitValid; validateMRZResultModel.IsDateOfBirthCrossCheckValid = res.IsDateOfBirthCrossCheckValid; validateMRZResultModel.IsDateOfExpiryCheckDigitValid = res.IsDateOfExpiryCheckDigitValid; validateMRZResultModel.IsDateOfExpiryCrossCheckValid = res.IsDateOfExpiryCrossCheckValid; validateMRZResultModel.IsFinalCheckDigitValid = res.IsFinalCheckDigitValid; validateMRZResultModel.IsGenderCrossCheckValid = res.IsGenderCrossCheckValid; validateMRZResultModel.IsNationalitCrossCheckValid = res.IsNationalitCrossCheckValid; validateMRZResultModel.IsPassportNumberCheckDigitValid = res.IsPassportNumberCheckDigitValid; validateMRZResultModel.IsPassportNumberCrossCheckValid = res.IsPassportNumberCrossCheckValid; validateMRZResultModel.IsPersonalNumberCrossCheckValid = res.IsPersonalNumberCrossCheckValid; validateMRZResultModel.IsServiceAvailable = res.IsServiceAvailable; return(View("Results", validateMRZResultModel)); } // Error occurred in data form // Becasue ValidateInput=false encode values before displaying mrzDataCaptureModel.PassportNumber = HttpUtility.HtmlEncode(mrzDataCaptureModel.PassportNumber); mrzDataCaptureModel.Nationality = HttpUtility.HtmlEncode(mrzDataCaptureModel.Nationality); mrzDataCaptureModel.DateOfBirth = HttpUtility.HtmlEncode(mrzDataCaptureModel.DateOfBirth); mrzDataCaptureModel.Gender = mrzDataCaptureModel.Gender; mrzDataCaptureModel.GenderItems = GetGenders(); mrzDataCaptureModel.DateOfExpiry = HttpUtility.HtmlEncode(mrzDataCaptureModel.DateOfExpiry); mrzDataCaptureModel.MRZ = HttpUtility.HtmlEncode(mrzDataCaptureModel.MRZ); return(View(mrzDataCaptureModel)); }
public void Return_All_True_If_Valid_Check_Digits_And_Valid_Data() { // assign string mrz = "9991263238GBR9102033M2302281<<<<<<<<<<<<<<02"; string passportNumber = "999126323"; string nationality = "GBR"; string dateOfBirth = "910203"; string gender = "M"; string dateOfExpiry = "230228"; string personalNumber = "<<<<<<<<<<<<<<"; // act var result = validate.ValidateMRZ(mrz, passportNumber, nationality, dateOfBirth, gender, dateOfExpiry, personalNumber); // assert Assert.AreEqual(true, result.IsPersonalNumberCheckDigitValid); Assert.AreEqual(true, result.IsPersonalNumberCrossCheckValid); Assert.AreEqual(true, result.IsDateOfBirthCheckDigitValid); Assert.AreEqual(true, result.IsDateOfBirthCrossCheckValid); Assert.AreEqual(true, result.IsDateOfExpiryCheckDigitValid); Assert.AreEqual(true, result.IsDateOfExpiryCrossCheckValid); Assert.AreEqual(true, result.IsFinalCheckDigitValid); Assert.AreEqual(true, result.IsGenderCrossCheckValid); Assert.AreEqual(true, result.IsNationalitCrossCheckValid); Assert.AreEqual(true, result.IsPassportNumberCheckDigitValid); Assert.AreEqual(true, result.IsPassportNumberCrossCheckValid); }