Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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);
        }