예제 #1
0
        public void OK3()
        {
            var validator = new ValidateMethodAttribute(
                typeof(ValidateMethodAttributeTest), nameof(this.Validate));

            validator.InternalValidateElement(null);
        }
예제 #2
0
        public void InvalidArgumentType()
        {
            var validator = new ValidateMethodAttribute(
                typeof(ValidateMethodAttributeTest), nameof(this.Validate));

            Assert.ThrowsException <InvalidCastException>(() =>
            {
                // 1 can't cast to TestClass
                validator.InternalValidateElement(1);
            });
        }
예제 #3
0
        public void OK2()
        {
            var validator = new ValidateMethodAttribute(
                typeof(ValidateMethodAttributeTest), nameof(this.Validate2));

            var value = new TestClass {
                Value = 1
            };

            validator.InternalValidateElement(value);

            Assert.IsTrue(value.Called);
        }
예제 #4
0
        public void NG()
        {
            var validator = new ValidateMethodAttribute(
                typeof(ValidateMethodAttributeTest), nameof(this.Validate));

            var value = new TestClass {
                Value = -1
            };

            Assert.ThrowsException <ValidationMetadataException>(() =>
            {
                validator.InternalValidateElement(value);
            });

            Assert.IsTrue(value.Called);
        }