Exemple #1
0
        public void LengthBetween_ShouldThrowIfTheLengthIsNotBetweenTheGivenValues()
        {
            IParameterValidator validator = new LengthBetweenAttribute(min: 1, max: 3);

            Assert.DoesNotThrow(() => validator.Validate(GetDummyParamInfo(), new int[1], null));
            Assert.DoesNotThrow(() => validator.Validate(GetDummyParamInfo(), new int[3], null));

            Assert.Throws <ValidationException>(() => validator.Validate(GetDummyParamInfo(), new int[0], null), Errors.INVALID_PARAM_LENGTH);
            Assert.Throws <ValidationException>(() => validator.Validate(GetDummyParamInfo(), new int[4], null), Errors.INVALID_PARAM_LENGTH);
        }
        public void LengthBetween_ShouldThrowIfTheLengthIsNotBetweenTheGivenValues()
        {
            PropertyInfo prop = GetType().GetProperty(nameof(EmptyValues), BindingFlags.Public | BindingFlags.Static);

            IPropertyValidator validator = new LengthBetweenAttribute(min: 1, max: 3);

            Assert.DoesNotThrow(() => validator.Validate(prop, new int[1], null));
            Assert.DoesNotThrow(() => validator.Validate(prop, new int[3], null));

            Assert.Throws <ValidationException>(() => validator.Validate(prop, new int[0], null), Errors.INVALID_PROPERTY_LENGTH);
            Assert.Throws <ValidationException>(() => validator.Validate(prop, new int[4], null), Errors.INVALID_PROPERTY_LENGTH);
        }