public void HasMessage() { var notification = new Notification(); Assert.IsFalse(notification.HasMessage("field", "message"), "message should not exist yet"); notification.Register("field", "message"); Assert.IsTrue(notification.HasMessage("field", "message"), "message should exist"); }
public void GetJoinedMessage() { var notification = new Notification(); notification.Register("field1", "message1"); notification.Register("field1", "message2"); Assert.AreEqual("message1, message2", notification.GetMessageFor("field1", ", ")); }
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; }
public void FieldsWithErrors() { var notification = new Notification(); notification.Register("field1", "message1"); notification.Register("field2", "message2"); Assert.AreEqual(new[] { "field1", "field2" }, notification.GetFieldsWithMessages()); }
public void GetMessages() { var notification = new Notification(); notification.Register("field1", "message1"); notification.Register("field2", "message2"); notification.Register("field1", "message3"); var messages = notification.GetMessagesFor("field1"); Assert.AreEqual(new[] { "message1", "message3" }, messages); }
public static Notification ValidateProperty(object obj, string propertyName) { var notification = new Notification(); var property = obj.GetType().GetProperty(propertyName, Bindings); if (property == null) throw new ArgumentException("Invalid property name:" + propertyName); ValidateProperty(obj, property, notification); return notification; }
public static Notification Validate(object obj) { var notification = new Notification(); var properties = obj.GetType().GetProperties(Bindings); foreach (PropertyInfo property in properties) { ValidateProperty(obj, property, notification); } return notification; }
public void IsNotValidWhenNotEmpty() { var notification = new Notification(); notification.Register("field", "message"); Assert.IsFalse(notification.IsValid); }
public void EmptyGetMessages() { var notification = new Notification(); Assert.AreEqual(0, notification.GetMessagesFor("field").Length); }
private static void ValidateProperty(object obj, PropertyInfo property, Notification notification) { if (!DependencySatisfied(obj, property)) return; foreach (ValidationAttribute validationRule in GetValidationAttributes(obj, property)) { validationRule.Property = property; validationRule.Validate(obj, notification); } }
public void Validate(object target, Notification notification) { var rawValue = Property.GetValue(target, null); if (!IsValid(rawValue)) notification.Register(Property.Name, Message); }