public void TestObjectOne_ValidCases(decimal?propertyOne, string propertyTwo) { //Arrange var testObject = new TestObjectOne(); testObject.PropertyOne = propertyOne; testObject.PropertyTwo = propertyTwo; //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 TestObjectOne_InValidCasesMessage(decimal?propertyOne, string propertyTwo) { //Arrange var testObject = new TestObjectOne(); testObject.PropertyOne = propertyOne; testObject.PropertyTwo = propertyTwo; //Act var validationResults = new List <ValidationResult>(); var ctx = new ValidationContext(testObject, null, null); Validator.TryValidateObject(testObject, ctx, validationResults, true); //Assert Assert.AreEqual("PropertyOne must have value, when PropertyTwo has value", validationResults[0].ErrorMessage); }
public void IsValidWhenPropertyOneIsTestValue(string propertyTwo, string propertyThree) { //Arrange var testObject = new TestObjectOne(); testObject.PropertyOne = "TestValue"; testObject.PropertyTwo = propertyTwo; testObject.PropertyThree = propertyThree; //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 IsNotValidWhenBothBlankAndPropertyOneIsTestValue_ExpectedMessage(string propertyTwo, string propertyThree, string expected) { //Arrange var testObject = new TestObjectOne(); testObject.PropertyOne = "TestValue"; testObject.PropertyTwo = propertyTwo; testObject.PropertyThree = propertyThree; //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); }