public static bool Validate(string countryCode, string zipCode) { // Validate if (string.IsNullOrWhiteSpace(countryCode)) { throw new Exception("Invalid country code passed for zip validation."); } if (string.IsNullOrWhiteSpace(zipCode)) { throw new Exception("Null or empty zip code passed for validation."); } // Extract patterns var validationEntry = CountryZipValidatorPatterns.FirstOrDefault(x => x.Key == countryCode.Trim()); var patterns = validationEntry.Value; //Create strategy IValidatorStrategy strategy = new RegexValidatorStrategy(patterns, true); // Validate return(strategy.Validate(zipCode.Trim())); }
public void NullPatternTest() { var _strategy = new RegexValidatorStrategy(true); Assert.ThrowsException<Exception>(() => _strategy.Validate(null, "123")); }
public void EmptyPatternTest() { var _strategy = new RegexValidatorStrategy(true); Assert.ThrowsException<Exception>( () => _strategy.Validate(new List<string>(), "123")); }