コード例 #1
0
        public void PropertyShouldReturnSameBuilderForExpression()
        {
            // arrange
            var validator = new ObjectValidator<IComponent>();

            // act
            var expected = validator.Property( c => c.Site );
            var actual = validator.Property( c => c.Site );

            // assert
            Assert.Same( expected, actual );
        }
コード例 #2
0
        public void PropertyShouldNotAllowNullExpression()
        {
            // arrange
            var validator = new ObjectValidator<IComponent>();
            Expression<Func<IComponent, ISite>> propertyExpression = null;

            // act
            var ex = Assert.Throws<ArgumentNullException>( () => validator.Property( propertyExpression ) );

            // assert
            Assert.Equal( "propertyExpression", ex.ParamName );
        }
コード例 #3
0
        public void ValidatePropertyShouldReturnExpectedResult()
        {
            // arrange
            var validator = new ObjectValidator<IComponent>();

            validator.Property( c => c.Site ).Required();

            // act
            var actual = validator.ValidateProperty( "Site", null );

            // assert
            Assert.Equal( 1, actual.Count );
            Assert.Equal( "Site", actual[0].MemberNames.Single() );
        }
コード例 #4
0
        public void ValidateObjectShouldValidateSpecifiedProperties()
        {
            // arrange
            var instance = new Mock<IComponent>().Object;
            var validator = new ObjectValidator<IComponent>();
            var propertyNames = new[] { "Site" };

            validator.Property( c => c.Site ).Required();

            // act
            var actual = validator.ValidateObject( instance, propertyNames );

            // assert
            Assert.Equal( 1, actual.Count );
            Assert.Equal( "Site", actual[0].MemberNames.Single() );
        }