Пример #1
0
 public static Notification GetNotification(ValidationAttribute attribute, object caller, string propertyName)
 {
     var notification = new Notification();
     attribute.Property = caller.GetType().GetProperty(propertyName);
     attribute.Validate(caller, notification);
     return notification;
 }
Пример #2
0
        public static void ThrowsException(ValidationAttribute attribute, object caller, string propertyName, Type expectedException)
        {
            attribute.Property = caller.GetType().GetProperty(propertyName);
            try
            {
                attribute.Validate(caller, new Notification());
                Assert.Fail("Expected exception");
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(AssertionException))
                    throw;

                Assert.IsInstanceOfType(expectedException, ex);
            }
        }
Пример #3
0
 private static void AssertValidation(ValidationAttribute attribute, object caller, 
     string propertyName, Action<bool> asserter)
 {
     var notification = GetNotification(attribute, caller, propertyName);
     asserter(notification.HasMessage(propertyName, attribute.Message));
 }
Пример #4
0
 public static void IsValid(ValidationAttribute attribute, object caller, string propertyName)
 {
     AssertValidation(attribute, caller, propertyName, Assert.IsFalse);
 }