Ejemplo 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;

                bool exceptionThrown = false;

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

                Assert.IsFalse(exceptionThrown);
            }
Ejemplo n.º 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);
            }
Ejemplo n.º 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));
            }
Ejemplo n.º 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"));
            }
Ejemplo n.º 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"));
            }
Ejemplo n.º 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"));
            }
Ejemplo n.º 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"));
            }