示例#1
0
        public void TestProjectController_ProjectAddressValidation(string httpMethod)
        {
            SetUpProjectControllerForTesting(httpMethod);
            projectController.CurrentUser = user;

            string result = projectController.ProjectAddressValidation(projectId);

            var jo     = Newtonsoft.Json.Linq.JObject.Parse(result);
            var errors = jo["errors"];

            Assert.That(result, Is.Not.EqualTo(string.Empty));

            List <string> errorList = new List <string>
            {
                "Address Line 1",
                "City",
                "Zip Code",
                "Country",
                "State/Province"
            };

            if (errors.ToArray().Count() > 0)
            {
                for (int i = 0; i < errors.ToArray().Count(); i++)
                {
                    var innerErrors = Newtonsoft.Json.Linq.JObject.Parse(errors[i].ToString());

                    for (int a = 0; a < innerErrors["errors"].ToArray().Count(); a++)
                    {
                        switch (a)
                        {
                        case 0:
                            Assert.That(innerErrors["errors"].ToArray()[a].ToString(), Is.Not.EqualTo(string.Empty));
                            break;

                        case 1:
                            Assert.That(errorList.Contains(innerErrors["errors"].ToArray()[a].ToString()), Is.EqualTo(true));
                            break;

                        case 2:
                            Assert.That(errorList.Contains(innerErrors["errors"].ToArray()[a].ToString()), Is.EqualTo(true));
                            break;

                        case 3:
                            Assert.That(errorList.Contains(innerErrors["errors"].ToArray()[a].ToString()), Is.EqualTo(true));
                            break;

                        case 4:
                            Assert.That(errorList.Contains(innerErrors["errors"].ToArray()[a].ToString()), Is.EqualTo(true));
                            break;

                        case 5:
                            Assert.That(errorList.Contains(innerErrors["errors"].ToArray()[a].ToString()), Is.EqualTo(true));
                            break;
                        }
                    }
                }
            }
        }