public void AllValid() { V.IValidationHelper validationHelper = new V.ValidationHelper(); ValidationObj obj = new ValidationObj { Name = "ThisIsValid", Number = 777, Other = "Present" }; string errorMessage = String.Empty; bool exceptionThrown = false; try { validationHelper.Validate(obj); } catch (ValidationException) { exceptionThrown = true; } Assert.IsFalse(exceptionThrown); }
public void NotValid() { V.IValidationHelper validationHelper = new V.ValidationHelper(); ValidationObj obj = new ValidationObj { Name = "All these fields are invalid!", Number = 10000000, }; bool exceptionThrown = false; try { validationHelper.Validate(obj); } catch (ValidationException vEx) { exceptionThrown = true; Assert.IsFalse(String.IsNullOrWhiteSpace(vEx.Message)); Assert.IsTrue(vEx.Message.Contains("maximum")); // Name Assert.IsTrue(vEx.Message.Contains("between")); // Number Assert.IsTrue(vEx.Message.Contains("required")); // Other } Assert.IsTrue(exceptionThrown); }
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")); }