IBAN: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 548: | Line 548: | ||
var countryCode = value.Substring(0, 2).ToUpper(); |
var countryCode = value.Substring(0, 2).ToUpper(); |
||
int lengthForCountryCode; |
|||
var countryCodeKnown = _lengths.TryGetValue(countryCode, out lengthForCountryCode); |
|||
if (!countryCodeKnown) |
|||
{ |
|||
return IbanValidationResult.CountryCodeNotKnown; |
|||
} |
|||
// Check length. |
// Check length. |
||
if (value.Length < lengthForCountryCode) |
if (value.Length < lengthForCountryCode) |
||
Line 568: | Line 576: | ||
return ValidationResult.IsValid; |
return ValidationResult.IsValid; |
||
} |
|||
public enum ValidationResult |
|||
{ |
|||
IsValid, |
|||
ValueMissing, |
|||
ValueTooSmall, |
|||
ValueTooBig, |
|||
ValueFailsModule97Check, |
|||
CountryCodeNotKnown |
|||
} |
} |
||
Line 696: | Line 714: | ||
// Assert |
// Assert |
||
Assert.Equal(ValidationResult.ValueFailsModule97Check, result); |
Assert.Equal(ValidationResult.ValueFailsModule97Check, result); |
||
} |
|||
[Fact] |
|||
public void It_should_return_an_error_when_an_unkown_country_prefix_used() |
|||
{ |
|||
// Assert |
|||
const string value = "XX82WEST12345698765432"; |
|||
var validator = new IbanValidator(); |
|||
// Act |
|||
var result = validator.Validate(value); |
|||
// Assert |
|||
Assert.Equal(ValidationResult.CountryCodeNotKnown, result); |
|||
} |
} |
||