public void PhoneNumberValidatorIsValidTestNoInputReturnsFalse(PhoneNumberType type, string input) { var ctx = CreateContext(input); var sut = new PhoneNumberValidator <Dummy>(type); sut.IsValid(ctx, input).Should().BeFalse(); }
public void PhoneNumberValidatorIsValidTestUKInvalidValueFails(string input) { var ctx = CreateContext(input); var sut = new PhoneNumberValidator <Dummy>(PhoneNumberType.UK); sut.IsValid(ctx, input).Should().BeFalse(); }
public async Task PhoneValidator() { var em1 = await TestFns.NewEm(_serviceName); var custType = em1.MetadataStore.GetEntityType(typeof(Customer)); var validator = new PhoneNumberValidator(); var validators = custType.GetDataProperty("Address").Validators; try { validators.Add(validator); var cust = new Customer() { CompanyName = "Foo" }; em1.AddEntity(cust); var valErrors = cust.EntityAspect.ValidationErrors; CustPropValAssert(cust, "asdf", 1); Assert.IsTrue(valErrors.First().Message.Contains("phone number")); CustPropValAssert(cust, "Pennsylvania 6500", 1); CustPropValAssert(cust, "5", 1); // missing '.com' CustPropValAssert(cust, null, 0); CustPropValAssert(cust, "(510) 686-8275", 0); CustPropValAssert(cust, "01 510 686-8275", 0); CustPropValAssert(cust, "+1 510 686-8275", 0); // // these pass too. You might not expect that CustPropValAssert(cust, "51", 0); CustPropValAssert(cust, "1234567", 0); CustPropValAssert(cust, "12345678901234567890123456789", 0); } finally { validators.Remove(validator); } }
private List <string> ValidatePhoneNumbers(List <string> phoneNumbers) { Validator.IsTrue <ArgumentException>( phoneNumbers != null && phoneNumbers.Count > 0, nameof(phoneNumbers), "Empty phone number"); Validator.IsTrue <ArgumentException>( phoneNumbers != null && phoneNumbers.Count <= SmsConstant.TargetMaxSize, nameof(phoneNumbers), "Too many phone numbers"); var filtered = phoneNumbers.Distinct().ToList(); var invalid = filtered.Where(n => !PhoneNumberValidator.IsNumberValid(n)).ToList(); Validator.IsTrue <ArgumentException>( invalid.Count <= 0, nameof(invalid), "Phone number formatted incorrectly: {0}", string.Join(",", invalid)); return(filtered); }
public void PhoneNumberValidatorIsValidTestIntInvalidValueSucceeds(string input) { var ctx = CreateContext(input); var sut = new PhoneNumberValidator <Dummy>(PhoneNumberType.International); sut.IsValid(ctx, input).Should().BeTrue(); }
private void CreateValidators() { DataAccess = new ContactDataAccess(); var phoneValidator = new PhoneNumberValidator("areaCode.txt"); Validator = new RolodexValidator(phoneValidator); }
public void ShouldReturnTrueForValidNumber(CallConnectModel model) { var phoneValidator = new PhoneNumberValidator(); var result = phoneValidator.Validate(model); Assert.True(result); }
public void PhoneNumberValidatorConstructorTest(PhoneNumberType type) { var sut = new PhoneNumberValidator <Dummy>(type); sut.Name.Should().Be("PhoneNumberValidator"); sut.Type.Should().Be(type); }
public ConfirmationController(SmsConfirmationCodeManager smsConfirmationCodeManager, ConfirmationTokenManager confirmationTokenManager, PhoneNumberValidator phoneNumberValidator) { this.smsConfirmationCodeManager = smsConfirmationCodeManager; this.confirmationTokenManager = confirmationTokenManager; this.phoneNumberValidator = phoneNumberValidator; }
public void SlashIsNotAValidSeparator() { const string input = "123/456/7890"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsFalse(isValid); }
public void IfIsNotValidPhoneNumber(string phoneNumber) { if (!PhoneNumberValidator.Validate(phoneNumber)) { var exceptionMsg = string.Format(DefaultIfIsNotValidPhoneNumberMessage, phoneNumber); throw new ArgumentException(exceptionMsg); } }
public void FirstSegmentShouldBeOptional() { const string input = "456-7890"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsTrue(isValid); }
public void Test_MobilisNumberWithAreaCode_Invalid() { var validator = new PhoneNumberValidator() .FromString("00213(0)0662175032") .WithMask("00213(0)6########"); Assert.IsFalse(validator.IsValid()); }
public void SegmentsWithDotsShouldBeValid() { const string input = "123.456.7890"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsTrue(isValid); }
public void LessThan10DigitsShouldBeInvalid() { const string input = "1234567"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsFalse(isValid); }
public void NotEnoughSeparatorsShouldBeInvalid() { const string input = "123-4567890"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsFalse(isValid); }
public void IfIsNotValidPhoneNumber(string phoneNumber, string argumentName, string message = null) { if (!PhoneNumberValidator.Validate(phoneNumber)) { var exceptionMsg = message ?? string.Format(DefaultIfIsNotValidPhoneNumberMessage, phoneNumber); throw new ArgumentException(exceptionMsg, argumentName); } }
public void AllDigitsShouldBeValid() { const string input = "1234567890"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsTrue(isValid); }
public void TwoDigitSecondSegmentWithAltSeparatorShouldBeInvalid() { const string input = "123.45.6789"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsFalse(isValid); }
public void Test_MobilisNumberWithoutAreaCode_Valid() { var validator = new PhoneNumberValidator() .FromString("0662175032") .WithMask("06########"); Assert.IsTrue(validator.IsValid()); }
public AuthenticationController(UsersRepository usersRepository, JwtTokenProvider tokenProvider, PhoneNumberValidator phoneNumberValidator) { this.usersRepository = usersRepository; this.tokenProvider = tokenProvider; this.phoneNumberValidator = phoneNumberValidator; }
public void WhitespaceAfterFirstSegmentShouldBeValid() { const string input = "(123) 456.7890"; var validator = new PhoneNumberValidator(); var isValid = validator.Validate(input); Assert.IsTrue(isValid); }
public void Test_DjezzyNumberWithAreaCode_Valid() { var validator = new PhoneNumberValidator() .FromString("+213770175032") .WithMask("002137########") .WithMask("+2137########"); Assert.IsTrue(validator.IsValid()); }
public ServicesController(ServicesRepository servicesRepository, UsersRepository usersRepository, UserFilter userFilter, PhoneNumberValidator phoneNumberValidator) { this.servicesRepository = servicesRepository; this.usersRepository = usersRepository; this.userFilter = userFilter; this.phoneNumberValidator = phoneNumberValidator; }
private static void ValidatePhoneNumber(string phoneNumber) { var validator = new PhoneNumberValidator(); var result = validator.Validate(phoneNumber); if (!result.IsValid) { throw new IdentityDomainException(nameof(phoneNumber)); } }
public void PhoneNumberValidatorTest(string phoneNumber) { // Arrange // phoneNumbers are in testcase // Act bool result = PhoneNumberValidator.IsPhoneNumberValid(phoneNumber); // Assert Assert.IsTrue(result); }
public void AssertInvalidPhoneNumbers( [Values( "206--555-0144", "222-288--44-44", "(222))-288-44-44", "222 288 44 44")] string phoneNo) { PhoneNumberValidator phoneNumberValidator = new PhoneNumberValidator(); Assert.AreEqual(false, phoneNumberValidator.IsValid(phoneNo), string.Format(CultureInfo.CurrentCulture, "The phone number '{0}' should be invalid", phoneNo)); }
private void PhoneNumberEntryChanged(object sender, TextChangedEventArgs e) { Entry entry = (Entry)sender; if (PhoneNumberValidator.IsPhoneNumberValid(entry.Text)) { entry.TextColor = Color.Black; } else { entry.TextColor = Color.Red; } }
public void Test_MobilisNumberOptional_InValid() { var validator = new PhoneNumberValidator() .FromString("00213(0)07505050") .IsOptional() .WithMask("06########") .WithMask("00213(0)6########") .WithMask("002136########") .WithMask("+2136########") .WithMask("+213(0)6########"); Assert.IsFalse(validator.IsValid()); }
public void PhoneNumberValidator() { var validator = _serviceProvider.GetService <IValidator>(); _testLeadEntity.Properties = new IProperty[] { new DefaultProperty(Modules.LeadEntity.Interface.Constants.PropertyKeys.PhoneNumber, "888-888-8888") }; var phoneNumber = new PhoneNumberValidator(); phoneNumber.ValidLead(_testLeadEntity); bool expectedValue = false; var actualValue = validator.ValidLead(_testLeadEntity); Assert.AreEqual(expectedValue, actualValue); }
public async Task EmployeeMustHaveValidUSPhone() { var manager = new EntityManager(_serviceName); // new empty EntityManager await manager.FetchMetadata(); // required before creating a new entity var employeeType = manager.MetadataStore.GetEntityType(typeof(Employee)); //get the Employee type var phoneValidator = new PhoneNumberValidator(); // or the hard way ... :) // var phoneValidator = new RegexValidator(@"^((\([2-9]\d{2}\) ?)|([2-9]\d{2}[-.]))\d{3}[-.]\d{4}$", "phone number"); // email pattern try { // add regex validator that validates emails to the HomePhone property employeeType.GetProperty("HomePhone").Validators.Add(phoneValidator); var employee = new Employee { FirstName = "Jane", LastName = "Doe" }; employee.HomePhone = "N2L 3G1"; // a bad phone number // force validation of unattached employee manager.AttachEntity(employee); var errors = employee.EntityAspect.ValidationErrors; Assert.IsTrue(errors.Any(), String.Format("should have 1 error: {0}", errors.First().Message)); employee.HomePhone = "510-555-1111"; Assert.IsFalse(errors.Any(), String.Format("should have no errors")); } finally { Assert.IsTrue(employeeType.GetProperty("HomePhone").Validators.Remove(phoneValidator)); } }