Example #1
0
        public void GetItemTest_Negative()
        {
            try
            {
                var model = new PatientFakeModel
                {
                    FirstName = string.Empty, //empty string validation error
                    LastName  = null,         //empty string validation error
                    Age       = 50,
                    Email     = "*****@*****.**",
                    Symptoms  = new List <string> {
                        "symptom 1", "symptom 2", "symptom 3"
                    }
                };

                var modelState = ModelValidator.Validate(model);
                var item       = modelState["Email"];
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Example #2
0
        public void TryGetValueTest()
        {
            var model = new PatientFakeModel
            {
                FirstName = "Erika",
                LastName  = null,//empty validation error
                Age       = 24,
                Email     = "*****@*****.**",
                Symptoms  = new List <string> {
                    "symptom 1", "symptom 2", "symptom 3"
                }
            };

            var modelState = ModelValidator.Validate(model);
            IValidationResult validationResult;

            if (modelState.TryGetValue("LastName", out validationResult))
            {
                if (validationResult == null || validationResult.Errors.Count == 0)
                {
                    Assert.Fail();
                }
            }
            else
            {
                Assert.Fail();
            }
        }
Example #3
0
        public void GetKeysTest()
        {
            var model = new PatientFakeModel
            {
                FirstName = "Erika",
                LastName  = "Cole",
                Age       = 106,                //age validation error
                Email     = "*****@*****.**",
                Symptoms  = new List <string>() //min lenght validation error
            };

            var modelState = ModelValidator.Validate(model);

            Assert.AreEqual(modelState.Keys.Count(), 2);
        }
Example #4
0
        public void GetItemTest_Positive()
        {
            var model = new PatientFakeModel
            {
                FirstName = string.Empty, //empty string validation error
                LastName  = null,         //empty string validation error
                Age       = 50,
                Email     = "*****@*****.**",
                Symptoms  = new List <string> {
                    "symptom 1", "symptom 2", "symptom 3"
                }
            };

            var modelState = ModelValidator.Validate(model);

            Assert.AreEqual(modelState["FirstName"].Errors.Count, 1);
            Assert.AreEqual(modelState["LastName"].Errors.Count, 1);
        }
Example #5
0
        public void GetEnumeratorTest()
        {
            var model = new PatientFakeModel
            {
                FirstName = "Erika",
                LastName  = "Cole",
                Age       = 106,                //age validation error
                Email     = "*****@*****.**",
                Symptoms  = new List <string>() //min lenght validation error
            };

            var modelState      = ModelValidator.Validate(model);
            int countOfElements = 0;

            using (var enumerator = modelState.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    countOfElements++;
                }
            }

            Assert.AreEqual(countOfElements, 2);
        }