コード例 #1
0
        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 );
        }
コード例 #2
0
        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 );
        }
コード例 #3
0
        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 );
        }
コード例 #4
0
        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() );
        }