public void EvaluateShouldReturnSuccessForValueMatchingPattern() { // arrange var rule = new RegularExpressionRule( @"\d{3}-\d{2}-\d{4}" ); var property = new Property<string>( "Ssn", "111-22-3333" ); var expected = ValidationResult.Success; // act var actual = rule.Evaluate( property ); // assert Assert.Equal( expected, actual ); }
public void EvaluateShouldReturnSuccessForNullValue() { // arrange var rule = new RegularExpressionRule( ".+" ); var property = new Property<string>( "Ssn", null ); var expected = ValidationResult.Success; // act var actual = rule.Evaluate( property ); // assert Assert.Equal( expected, actual ); }
public void EvaluateShouldReturnResultWithCustomErrorMessage() { // arrange var expected = "Invalid"; var rule = new RegularExpressionRule( @"\d{3}-\d{2}-\d{4}", expected ); var property = new Property<string>( "Ssn", "111-xx-3333" ); // act var actual = rule.Evaluate( property ); // assert Assert.Equal( expected, actual.ErrorMessage ); }
public void EvaluateShouldReturnExpectedResultForValueUnmatchedByPattern() { // arrange var rule = new RegularExpressionRule( @"\d{3}-\d{2}-\d{4}" ); var property = new Property<string>( "Ssn", "111-xx-3333" ); // act var actual = rule.Evaluate( property ); // assert Assert.Equal( @"The Ssn field must match the regular expression '\d{3}-\d{2}-\d{4}'.", actual.ErrorMessage ); Assert.Equal( 1, actual.MemberNames.Count() ); Assert.Equal( "Ssn", actual.MemberNames.Single() ); }