Example #1
0
        public void EmailValidationShouldFailWithErrorCode()
        {
            var target = new ModelValidator(_reflectionService);

            var complexModel = new ComplexModel("notavalidmail", "bbbbbbbbbbb");

            var validationResult = target.Validate(complexModel);

            var errorCode = validationResult[0]
                            .ErrorCodes[0];

            Assert.AreEqual(FieldValidationErrorCode.EmailAddress, errorCode);
            Assert.IsFalse(validationResult[0].IsValid);
        }
Example #2
0
        public void ValidationShouldSucceed()
        {
            var target = new ModelValidator(_reflectionService);

            var complexModel1 = new ComplexModel("*****@*****.**", "aaaaaaaaaaa");
            var complexModel2 = new ComplexModel("*****@*****.**", "bbbbbbbbbbb");
            var complexModels = new List <ComplexModel> {
                complexModel1, complexModel2
            };
            var testModel = new TestModel("nice", complexModels);

            var validationResult = target.Validate(testModel);
            var actual           = !validationResult.Any();

            Assert.IsTrue(actual);
        }
Example #3
0
        public void ListValidationShouldFailWithErrorCode()
        {
            var target = new ModelValidator(_reflectionService);

            var complexModel1 = new ComplexModel("*****@*****.**", "aaaaaaaaaaa");
            var complexModel2 = new ComplexModel("*****@*****.**", "bbbb");
            var complexModels = new List <ComplexModel> {
                complexModel1, complexModel2
            };
            var testModel = new TestModel("nice", complexModels);

            var validationResult = target.Validate(testModel);

            var errorCode = validationResult[0]
                            .SubFieldValidationResults[0]
                            .ErrorCodes[0];

            Assert.AreEqual(FieldValidationErrorCode.MinLength, errorCode);
            Assert.IsFalse(validationResult[0].IsValid);
        }