public void ValidationPassesForValidPostCodes() { PostCodeValidator validator = new PostCodeValidator("GB"); Assert.IsTrue(validator.IsValid(this, "DY13 9SB")); Assert.IsTrue(validator.IsValid(this, "S11 7EZ")); Assert.IsTrue(validator.IsValid(this, "SW12 0HF")); }
public void ValidationFailsForInvalidPostCodes() { PostCodeValidator validator = new PostCodeValidator("GB"); Assert.IsFalse(validator.IsValid(this, "A 1")); Assert.IsFalse(validator.IsValid(this, "AB 1A")); Assert.IsFalse(validator.IsValid(this, "1AB 2AB")); }
public void validate_postcode(string postCode, string message) { //Arrange var validator = new PostCodeValidator(postCode); //Act var result = validator.IsValidPostCode(); //Assert Assert.True(result, message); }
public void ValidateFailTest() { PostCodeValidator target = new PostCodeValidator(); string input = "123456"; IResult expected = ResultFactory.GetFailResultInstance("Postcode must be 5 digit only."); IResult actual; actual = target.Validate(input); Assert.AreEqual(expected.IsSuccess, actual.IsSuccess); }
public void ValidateSuccessTest() { PostCodeValidator target = new PostCodeValidator(); string input = "12345"; IResult expected = ResultFactory.GetSuccessResultInstance(); IResult actual; actual = target.Validate(input); Assert.AreEqual(expected.IsSuccess, actual.IsSuccess); }
public async Task Validate_InvalidPostCode_ReturnsInvalidResult() { var validApiResponse = new PostCodeValidationResponse { result = false }; SetupHttpClient(validApiResponse); _postCodeValidator = new PostCodeValidator(_httpClient, _config); var response = await _postCodeValidator.Validate("postCode"); Assert.IsFalse(response.result); }
/// <summary> /// I dont think the regex used covers overseas territories. This is because /// they use a different format some can have 4 letters with only 1 number. /// The regex given eensures a "9AA" ending which doesnt apply to Anguilla. /// Also in some other cases we have 4 characters together. Which will fail too. /// </summary> /// <param name="args"></param> static void Main(string[] args) { Console.WriteLine("Loading CSV"); var csv = File.ReadAllText("import_data.csv").Split('\n') .Select(line => line.Split(',')) .Where(line => line != null && line.Length > 1 && !line[0].Contains("row")) .ToDictionary(line => int.Parse(line[0]), line => line[1]); var failedCSV = new StringBuilder(); var successCSV = new StringBuilder(); var header = string.Format("{0},{1}", "row_id", "postcode"); failedCSV.AppendLine(header); successCSV.AppendLine(header); var validator = new PostCodeValidator(string.Empty); Console.WriteLine("Sorting CSV by id"); var orderedCSV = csv.OrderBy(dict => dict.Key); Console.WriteLine("Verifying PostCodes"); foreach (var row in orderedCSV) { validator.PostCodeToVerify = row.Value; var postcode = string.Format("{0},{1}", row.Key, row.Value); if (validator.IsValidPostCode()) { successCSV.AppendLine(postcode); } else { failedCSV.AppendLine(postcode); } } File.WriteAllText("succeeded_validations.csv", successCSV.ToString()); File.WriteAllText("failed_validation.csv", failedCSV.ToString()); Console.WriteLine("Validation Compelted Press a key to exit"); Console.Read(); }
public void ExceptionThrownForCulturesWithoutASpecifiedExpression() { PostCodeValidator validator = new PostCodeValidator("NI"); validator.IsValid(this, "abc"); }