Пример #1
0
        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());
        }
Пример #2
0
        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);
        }
Пример #3
0
        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());
        }
Пример #4
0
        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);
        }