Пример #1
0
        public void EvaluateShouldReturnSuccessForNonNullValue()
        {
            // arrange
            var rule = new RequiredRule<object>();
            var property = new Property<object>( "Object", new object() );
            var expected = ValidationResult.Success;

            // act
            var actual = rule.Evaluate( property );

            // assert
            Assert.Equal( expected, actual );
        }
Пример #2
0
        public void EvaluateShouldReturnSuccessForEmptyString()
        {
            // arrange
            var rule = new RequiredRule<string>() { AllowEmptyStrings = true };
            var property = new Property<string>( "Text", "" );
            var expected = ValidationResult.Success;

            // act
            var actual = rule.Evaluate( property );

            // assert
            Assert.Equal( expected, actual );
        }
Пример #3
0
        public void EvaluateShouldReturnExpectedResultForNullValue()
        {
            // arrange
            var rule = new RequiredRule<object>();
            var property = new Property<object>( "Object", null );

            // act
            var actual = rule.Evaluate( property );

            // assert
            Assert.Equal( "The Object field is required.", actual.ErrorMessage );
            Assert.Equal( 1, actual.MemberNames.Count() );
            Assert.Equal( "Object", actual.MemberNames.Single() );
        }
Пример #4
0
        public void EvaluateShouldReturnExpectedResultForNullOrEmptyString( string value )
        {
            // arrange
            var rule = new RequiredRule<string>();
            var property = new Property<string>( "Text", value );

            // act
            var actual = rule.Evaluate( property );

            // assert
            Assert.Equal( "The Text field is required.", actual.ErrorMessage );
            Assert.Equal( 1, actual.MemberNames.Count() );
            Assert.Equal( "Text", actual.MemberNames.Single() );
        }
Пример #5
0
        public void EvaluateShouldReturnResultWithCustomErrorMessageForString()
        {
            // arrange
            var expected = "Invalid";
            var rule = new RequiredRule<string>( expected );
            var property = new Property<string>( "Text", null );

            // act
            var actual = rule.Evaluate( property );

            // assert
            Assert.Equal( expected, actual.ErrorMessage );
        }