public void TestRequiredFails() { var poco = new POCO(); var context = new ValidationContext(poco) { MemberName = nameof(POCO.Required) }; var results = new List <ValidationResult>(); if (Validator.TryValidateProperty(poco.Required, context, results)) { Assert.Fail("Required was not required!!!"); } Assert.IsNotNull(results.FirstOrDefault(r => r.MemberNames.Any(m => m == nameof(POCO.Required)))); }
public void TestRequiredPasses() { var poco = new POCO(); poco.Required = "Not Empty"; var context = new ValidationContext(poco) { MemberName = nameof(POCO.Required) }; var results = new List <ValidationResult>(); if (!Validator.TryValidateProperty(poco.Required, context, results)) { Assert.Fail("Required was filled in"); } Assert.IsNull(results.FirstOrDefault(r => r.MemberNames.Any(m => m == nameof(POCO.Required)))); }
public void TestValidMethodFails() { var poco = new POCO(); var context = new ValidationContext(poco) { MemberName = nameof(POCO.Valid) }; var results = new List <ValidationResult>(); if (Validator.TryValidateProperty(poco.Valid, context, results)) { Assert.Fail("Valid Property Passed!!!"); } Assert.IsNotNull( results.FirstOrDefault( r => r.MemberNames.Any(m => m == nameof(POCO.Valid)) && r.ErrorMessage == Messages.ValidPropNotValid)); }