예제 #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;

                bool exceptionThrown = false;

                try
                {
                    validationHelper.Validate(obj);
                }
                catch (ValidationException)
                {
                    exceptionThrown = true;
                }

                Assert.IsFalse(exceptionThrown);
            }
예제 #2
0
            public void NotValid()
            {
                V.IValidationHelper validationHelper = new V.ValidationHelper();

                ValidationObj obj = new ValidationObj
                {
                    Name   = "All these fields are invalid!",
                    Number = 10000000,
                };

                bool exceptionThrown = false;

                try
                {
                    validationHelper.Validate(obj);
                }
                catch (ValidationException vEx)
                {
                    exceptionThrown = true;
                    Assert.IsFalse(String.IsNullOrWhiteSpace(vEx.Message));
                    Assert.IsTrue(vEx.Message.Contains("maximum"));    // Name
                    Assert.IsTrue(vEx.Message.Contains("between"));    // Number
                    Assert.IsTrue(vEx.Message.Contains("required"));   // Other
                }

                Assert.IsTrue(exceptionThrown);
            }
예제 #3
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));
            }
예제 #4
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"));
            }
예제 #5
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"));
            }
예제 #6
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"));
            }
예제 #7
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"));
            }