예제 #1
0
        public void GetValue(object item, bool expected)
        {
            //Arrange
            var testModel = new TestModel();

            //Act
            var value = IsDefaultValue.Value(item);

            //Assert
            Assert.AreEqual(expected, value);
        }
예제 #2
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);
     }
 }