Ejemplo n.º 1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if ((value is DateTime))
            {
                if ((DateTime)value != DateTime.MinValue)
                {
                    return(ValidationResult.Success);
                }
            }
            else if ((value != null) && (!string.IsNullOrWhiteSpace(value.ToString())))
            {
                return(ValidationResult.Success);
            }
            var model = validationContext.ObjectInstance;
            var otherPropertyValue = GetProperty.Value(model, otherProperty);

            if (otherPropertyValue == null)
            {
                return(ValidationResult.Success);
            }

            if (otherPropertyValue.ToString() == otherPropertyCheckTriggerValue)
            {
                return(new ValidationResult($"The {GetDisplayNameAttribute.Value(model, validationContext.MemberName)} field is required."));
            }
            return(ValidationResult.Success);
        }
Ejemplo n.º 2
0
        public void GetValue(string name, object expected)
        {
            //Arrange
            var testModel = new TestModel();

            //Act
            var value = GetDisplayNameAttribute.Value(testModel, name);

            //Assert
            Assert.AreEqual(expected, value);
        }
Ejemplo n.º 3
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var model = validationContext.ObjectInstance;
            var otherPropertyValue = GetProperty.Value(model, otherProperty);

            if (otherPropertyValue.Equals(value))
            {
                return(ValidationResult.Success);
            }
            var memberDisplayName        = GetDisplayNameAttribute.Value(model, validationContext.MemberName);
            var otherPropertyDisplayName = GetDisplayNameAttribute.Value(model, otherProperty);

            return(new ValidationResult($"{memberDisplayName} must match {otherPropertyDisplayName}."));
        }
Ejemplo n.º 4
0
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (!IsDefaultValue.Value(value))
     {
         return(ValidationResult.Success);
     }
     else
     {
         var model = validationContext.ObjectInstance;
         if (!IsDefaultValue.Value(GetProperty.Value(model, otherProperty)))
         {
             var memberDisplayName        = GetDisplayNameAttribute.Value(model, validationContext.MemberName);
             var otherPropertyDisplayName = GetDisplayNameAttribute.Value(model, otherProperty);
             return(new ValidationResult($"{memberDisplayName} must have value, when {otherPropertyDisplayName} has value."));
         }
         return(ValidationResult.Success);
     }
 }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var model = validationContext.ObjectInstance;
            var otherPropertyValue = GetProperty.Value(model, otherProperty);

            if (otherPropertyValue == null)
            {
                return(ValidationResult.Success);
            }

            if (value != null)
            {
                return(ValidationResult.Success);
            }

            if (!string.IsNullOrEmpty(otherPropertyValue.ToString().Trim()))
            {
                var memberDisplayName        = GetDisplayNameAttribute.Value(model, validationContext.MemberName);
                var otherPropertyDisplayName = GetDisplayNameAttribute.Value(model, otherProperty);
                return(new ValidationResult($"{memberDisplayName} must have value, when {otherPropertyDisplayName} has value"));
            }

            return(ValidationResult.Success);
        }