public void TestObjectTwo_InValidCasesMessage(decimal?propertyThree, string propertyFour) { //Arrange var testObject = new TestObjectTwo(); testObject.PropertyThree = propertyThree; testObject.PropertyFour = propertyFour; //Act var validationResults = new List <ValidationResult>(); var ctx = new ValidationContext(testObject, null, null); Validator.TryValidateObject(testObject, ctx, validationResults, true); //Assert Assert.AreEqual("Property Three must have value, when Property Four has value", validationResults[0].ErrorMessage); }
public void TestObjectTwo_ValidCases(decimal?propertyThree, string propertyFour) { //Arrange var testObject = new TestObjectTwo(); testObject.PropertyThree = propertyThree; testObject.PropertyFour = propertyFour; //Act var validationResults = new List <ValidationResult>(); var ctx = new ValidationContext(testObject, null, null); Validator.TryValidateObject(testObject, ctx, validationResults, true); //Assert Assert.AreEqual(0, validationResults.Count()); }
public void IsNotValidWhenBothBlankAndPropertyOneIsOtherTestValue_ExpectedMessage(string propertyFive, string propertySix, string expected) { //Arrange var testObject = new TestObjectTwo(); testObject.PropertyFour = "OtherTestValue"; testObject.PropertyFive = propertyFive; testObject.PropertySix = propertySix; //Act var validationResults = new List <ValidationResult>(); var ctx = new ValidationContext(testObject, null, null); Validator.TryValidateObject(testObject, ctx, validationResults, true); //Assert Assert.AreEqual(expected, validationResults[0].ErrorMessage); }