/// <summary> /// Determines whether the specified account number is valid. The given bank code will be /// mapped to an registered method which calculates the check digit. The account number /// is given as a full number including the hypothetical check digit. /// </summary> /// <param name="accountNumber">The account number including the hypothetical check digit.</param> /// <param name="validationErrors">Collection is filled up with the validation error messages</param> /// <returns> /// <c>true</c> if the specified account number is valid; otherwise, <c>false</c>. /// </returns> public bool Validate(NationalAccountNumber accountNumber, ICollection <ValidationError> validationErrors) { if (accountNumber == null) { throw new ArgumentNullException("accountNumber", "Please provide an account number."); } validationErrors = validationErrors ?? new List <ValidationError>(); var germanAccountNumber = new GermanyAccountNumber(accountNumber); ValidationMethodsTools.ValidateMember(germanAccountNumber.AccountNumber, 10, validationErrors, ValidationErrorCodes.AccountNumberMissing, ValidationErrorCodes.AccountNumberTooLong); ValidationMethodsTools.ValidateMember(germanAccountNumber.BankCode, 8, validationErrors, ValidationErrorCodes.BankCodeMissing, ValidationErrorCodes.BankCodeTooLong); if (validationErrors.Count > 0) { return(false); } var checkMethodCode = BankCodeMappingMethod.Resolve(germanAccountNumber.BankCode); if (string.IsNullOrEmpty(checkMethodCode)) { throw new ArgumentException(String.Format("Can't resolve the check method for the given bank code {0}.", germanAccountNumber.BankCode), "accountNumber"); } return(accountNumberValidationByMethodCode.IsValid(germanAccountNumber.AccountNumber, checkMethodCode)); }
public void Should_Validate_An_Account_Number_With_Method_01() { IAccountNumberValidationByMethodCode sut = SuT; Assert.IsTrue(sut.IsValid("4234322787", "01")); }