Esempio n. 1
0
            public void AllValid()
            {
                V.IValidationHelper validationHelper = new V.ValidationHelper();

                ValidationObj obj = new ValidationObj
                {
                    Name   = "ThisIsValid",
                    Number = 777,
                    Other  = "Present"
                };

                string errorMessage = String.Empty;

                Assert.IsTrue(validationHelper.TryValidate(obj, out errorMessage));
                Assert.IsTrue(String.IsNullOrWhiteSpace(errorMessage));
            }
Esempio n. 2
0
            public void MissingRequiredField()
            {
                V.IValidationHelper validationHelper = new V.ValidationHelper();

                ValidationObj obj = new ValidationObj
                {
                    Name   = "OtherMissing",
                    Number = 10
                };

                string errorMessage = String.Empty;

                Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage));

                Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage));
                Assert.IsTrue(errorMessage.Contains("required"));
            }
Esempio n. 3
0
            public void StringLengthTooLong()
            {
                V.IValidationHelper validationHelper = new V.ValidationHelper();

                ValidationObj obj = new ValidationObj
                {
                    Name   = "ThisIsJustAboutOver20",
                    Number = 21,
                    Other  = "Present"
                };

                string errorMessage = String.Empty;

                Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage));

                Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage));
                Assert.IsTrue(errorMessage.Contains("maximum"));
            }
Esempio n. 4
0
            public void NumberIsNegative()
            {
                V.IValidationHelper validationHelper = new V.ValidationHelper();

                ValidationObj obj = new ValidationObj
                {
                    Name   = "NegativeNumber",
                    Number = -777,
                    Other  = "Present"
                };

                string errorMessage = String.Empty;

                Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage));

                Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage));
                Assert.IsTrue(errorMessage.Contains("between"));
            }
Esempio n. 5
0
            public void StringLengthTooShort()
            {
                V.IValidationHelper validationHelper = new V.ValidationHelper();

                ValidationObj obj = new ValidationObj
                {
                    Name   = "min",
                    Number = 3,
                    Other  = "Present"
                };

                string errorMessage = String.Empty;

                Assert.IsFalse(validationHelper.TryValidate(obj, out errorMessage));

                Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage));
                Assert.IsTrue(errorMessage.Contains("minimum"));
            }
Esempio n. 6
0
            public void ValidateList()
            {
                V.IValidationHelper validationHelper = new V.ValidationHelper();

                var validationObjects = new List <ValidationObj>()
                {
                    new ValidationObj
                    {
                        Name   = "ThisIsValid",
                        Number = 777,
                        Other  = "Present"
                    },
                    new ValidationObj
                    {
                        Name   = "ThisIsNot",
                        Number = 0,
                    },
                };

                string errorMessage = String.Empty;

                Assert.IsFalse(validationHelper.TryValidate(validationObjects, out errorMessage));
                Assert.IsFalse(String.IsNullOrWhiteSpace(errorMessage));
            }