示例#1
0
        public void EvaluateShouldUseCustomErrorMessage()
        {
            // arrange
            var expected = "Test";
            var rule = new UrlRule( expected );
            var property = new Property<string>( "Url", "tempuri.org" );

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

            // assert
            Assert.Equal( expected, actual.ErrorMessage );
        }
示例#2
0
        public void EvaluateShouldReturnExpectedResultForInvalidValue()
        {
            // arrange
            var rule = new UrlRule();
            var property = new Property<string>( "Url", "foo" );

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

            // assert
            Assert.Equal( "The Url field is not a valid fully-qualified http, https, or ftp URL.", actual.ErrorMessage );
            Assert.Equal( 1, actual.MemberNames.Count() );
            Assert.Equal( "Url", actual.MemberNames.Single() );
        }
示例#3
0
        public void EvaluateShouldReturnSuccessForNullOrEmpty()
        {
            // arrange
            string value = null;
            var rule = new UrlRule();
            var property = new Property<string>( "Url", value );
            var expected = ValidationResult.Success;

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

            // assert
            Assert.Equal( expected, actual );
        }
示例#4
0
        public void EvaluateWithKindShouldReturnExpectedResultForValidValue()
        {
            // arrange
            var rule = new UrlRule( UriKind.Relative );
            var property = new Property<string>( "Url", "/api/helloworld" );
            var expected = ValidationResult.Success;

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

            // assert
            Assert.Equal( expected, actual );
        }
示例#5
0
        public void EvaluateShouldReturnExpectedResultForValidValue()
        {
            // arrange
            var rule = new UrlRule();
            var property = new Property<string>( "Url", "http://tempuri.org" );
            var expected = ValidationResult.Success;

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

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