public void IsIgnoreWithTest()
        {
            object value     = null;
            var    ableFalse = new IgnoreWhenNullable(false);

            Assert.False(ableFalse.IsIgnoreWith(value));

            value = 1;
            Assert.False(ableFalse.IsIgnoreWith(value));

            var parameter = TestParameter.Create(null);

            Assert.False(ableFalse.IsIgnoreWith(parameter));

            parameter = TestParameter.Create("laojiu");
            Assert.False(ableFalse.IsIgnoreWith(parameter));



            value = null;
            var ableTrue = new IgnoreWhenNullable(true);

            Assert.True(ableTrue.IsIgnoreWith(value));

            value = 1;
            Assert.False(ableTrue.IsIgnoreWith(value));

            parameter = TestParameter.Create(null);
            Assert.True(ableTrue.IsIgnoreWith(parameter));

            parameter = TestParameter.Create("laojiu");
            Assert.False(ableTrue.IsIgnoreWith(parameter));
        }
예제 #2
0
        public void ValidateParameterTest()
        {
            var parameter = TestParameter.Create();

            Assert.Throws <ValidationException>(() => DataValidator.ValidateParameter(parameter, null, true));

            parameter = TestParameter.Create();
            Assert.Throws <ValidationException>(() => DataValidator.ValidateParameter(parameter, new User {
            }, true));

            parameter = TestParameter.Create();
            DataValidator.ValidateParameter(parameter, new User {
                Account = "123"
            }, true);

            parameter = TestParameter.Create();
            Assert.Throws <ValidationException>(() => DataValidator.ValidateParameter(parameter, new User {
                Account = "123456"
            }, true));
        }