示例#1
0
        public void IsValid_GetValidationResult_ReturnsValidationResultWhenValueLengthIsLessThanSpecifiedMinimum(object value)
        {
            // Arrange
            ValidationContext          validationContext          = new ValidationContext(new { }, null, null);
            ValidateMinLengthAttribute validateMinLengthAttribute = new ValidateMinLengthAttribute(8, nameof(DummyStrings.Dummy), typeof(DummyStrings));

            // Act
            // IsValid is a protected function, the public function GetValidationResult calls it.
            ValidationResult validationResult = validateMinLengthAttribute.GetValidationResult(value, validationContext);

            // Assert
            Assert.Equal(DummyStrings.Dummy, validationResult.ErrorMessage);
        }
示例#2
0
        public void IsValid_GetValidationResult_ReturnsNullWhenValueLengthIsGreaterThanOrEqualToSpecifiedMinimumOrValueIsNullOrValueIsAnEmptyString(object value)
        {
            // Arrange
            ValidationContext          validationContext          = new ValidationContext(new { }, null, null);
            ValidateMinLengthAttribute validateMinLengthAttribute = new ValidateMinLengthAttribute(8, nameof(DummyStrings.Dummy), typeof(DummyStrings));

            // Act
            // IsValid is a protected function, the public function GetValidationResult calls it.
            ValidationResult validationResult = validateMinLengthAttribute.GetValidationResult(value, validationContext);

            // Assert
            Assert.Null(validationResult);
        }