public void AllValid() { V.IValidationHelper validationHelper = new V.ValidationHelper(); ValidationObj obj = new ValidationObj { Name = "ThisIsValid", Number = 777, Other = "Present" }; string errorMessage = String.Empty; Assert.IsTrue(validationHelper.TryValidate(obj, out errorMessage)); Assert.IsTrue(String.IsNullOrWhiteSpace(errorMessage)); }
public void MissingRequiredField() { V.IValidationHelper validationHelper = new V.ValidationHelper(); ValidationObj obj = new ValidationObj { Name = "OtherMissing", Number = 10 }; string errorMessage = String.Empty; Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage)); Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage)); Assert.IsTrue(errorMessage.Contains("required")); }
public void StringLengthTooLong() { V.IValidationHelper validationHelper = new V.ValidationHelper(); ValidationObj obj = new ValidationObj { Name = "ThisIsJustAboutOver20", Number = 21, Other = "Present" }; string errorMessage = String.Empty; Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage)); Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage)); Assert.IsTrue(errorMessage.Contains("maximum")); }
public void NumberIsNegative() { V.IValidationHelper validationHelper = new V.ValidationHelper(); ValidationObj obj = new ValidationObj { Name = "NegativeNumber", Number = -777, Other = "Present" }; string errorMessage = String.Empty; Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage)); Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage)); Assert.IsTrue(errorMessage.Contains("between")); }
public void StringLengthTooShort() { V.IValidationHelper validationHelper = new V.ValidationHelper(); ValidationObj obj = new ValidationObj { Name = "min", Number = 3, Other = "Present" }; string errorMessage = String.Empty; Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage)); Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage)); Assert.IsTrue(errorMessage.Contains("minimum")); }
public void ValidateList() { V.IValidationHelper validationHelper = new V.ValidationHelper(); var validationObjects = new List <ValidationObj>() { new ValidationObj { Name = "ThisIsValid", Number = 777, Other = "Present" }, new ValidationObj { Name = "ThisIsNot", Number = 0, }, }; string errorMessage = String.Empty; Assert.IsFalse(validationHelper.TryValidate(validationObjects, out errorMessage)); Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage)); }