Exemplo n.º 1
0
        public void MustAttribute_ShouldThrowIfThePredicateReturnsFalse()
        {
            IAsyncParameterValidator validator = new MustAttribute(typeof(NotNull));

            Assert.DoesNotThrow(() => validator.Validate(GetDummyParamInfo(), new object(), null));
            Assert.DoesNotThrowAsync(() => validator.ValidateAsync(GetDummyParamInfo(), new object(), null));

            Assert.Throws <ValidationException>(() => validator.Validate(GetDummyParamInfo(), null, null), Errors.VALIDATION_FAILED);
            Assert.ThrowsAsync <ValidationException>(() => validator.ValidateAsync(GetDummyParamInfo(), null, null), Errors.VALIDATION_FAILED);
        }
Exemplo n.º 2
0
        public void MustAttribute_ShouldThrowIfThePredicateReturnsFalse()
        {
            IAsyncPropertyValidator validator = new MustAttribute(typeof(NotNull));

            Assert.DoesNotThrow(() => validator.Validate(GetDummyPropInfo(), new object(), null));
            Assert.DoesNotThrowAsync(() => validator.ValidateAsync(GetDummyPropInfo(), new object(), null));

            Assert.Throws <ValidationException>(() => validator.Validate(GetDummyPropInfo(), null, null), Errors.VALIDATION_FAILED);
            Assert.ThrowsAsync <ValidationException>(() => validator.ValidateAsync(GetDummyPropInfo(), null, null), Errors.VALIDATION_FAILED);

            PropertyInfo GetDummyPropInfo() => typeof(ValidatorAttributeBase).GetProperties()[0];
        }