public override string GetObjectName(object element) { ThePropertyCollectionClass s = element as ThePropertyCollectionClass; if (s == null) { throw new ArgumentException(); } return(s.Name); }
public void ErrorsIncludeTheCollectionName() { TestableUniquePropertyCollectionValidator target = new TestableUniquePropertyCollectionValidator(); string collName = "The Collection"; ThePropertyCollectionClass coll = new ThePropertyCollectionClass(collName); coll.Add(new ThePropertyClass("same")); coll.Add(new ThePropertyClass("same")); ValidationResults result = target.Validate(coll); List <ValidationResult> results = new List <ValidationResult>(result); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, results.Count); Assert.IsTrue(results[0].Message.Contains(collName), "Message should contain the collection's name"); }
public void CollectionPassesValidation() { string badValue = "badvalue"; TestablePropertyCollectionValidator target = new TestablePropertyCollectionValidator(badValue); string collName = "The Collection"; ThePropertyCollectionClass coll = new ThePropertyCollectionClass(collName); coll.Add(new ThePropertyClass("value")); coll.Add(new ThePropertyClass("value")); ValidationResults result = target.Validate(coll); List <ValidationResult> results = new List <ValidationResult>(result); Assert.IsTrue(result.IsValid); Assert.AreEqual(0, results.Count); }