Пример #1
0
        public void RoadHelper_AddRoadStepOne_CheckIfAddRoadModelValid_BadArguments_GetFalse()
        {
            var client = new Mock<Roads.Web.Mvc.RoadsServiceClient.IRoadsService>();
            client.Setup(m => m.GetSearchingDepth()).Returns(10);

            var model = new AddRoadModel();
            model = RoadHelper.FillAddRoadModel(client.Object,model, new TestTranslationManager(), "en_En");
            ValidateDefaultAddRoadModel(model);

            bool result = RoadHelper.CheckIfAddRoadModelValid(ref model);
            Assert.IsFalse(result);
        }
Пример #2
0
        public void RoadHelper_AddRoadStepOne_CheckIfAddRoadModelValid_GoodArguments_GetTrue()
        {
            var client = new Mock<Roads.Web.Mvc.RoadsServiceClient.IRoadsService>();
            client.Setup(m => m.GetSearchingDepth()).Returns(10);

            var model = new AddRoadModel();
            model = RoadHelper.FillAddRoadModel(client.Object, model, new TestTranslationManager(), "en_En");
            ValidateDefaultAddRoadModel(model);

            // Modify Model
            model.CityPoints[0].CityName = "CityOne";
            model.CityPoints[0].CityId = "IdOne";
            model.CityPoints[1].CityName = "CityOne";
            model.CityPoints[1].CityId = "IdOne";

            bool result = RoadHelper.CheckIfAddRoadModelValid(ref model);
            Assert.IsTrue(result);
        }
Пример #3
0
 public void RoadHelper_AddRoadStepOne_CheckIfAddRoadModelValid_ArgumentsNull_CityPointsNull_GetException()
 {
     var model = new AddRoadModel();
     model.CityPoints = null;
     RoadHelper.CheckIfAddRoadModelValid( ref model);
 }
Пример #4
0
        protected internal static void ValidateDefaultAddRoadModel(AddRoadModel model)
        {
            Assert.IsNotNull(model);

            Assert.IsNotNull(model.CityPoints);
            Assert.AreEqual(2, model.CityPoints.Count);
            Assert.AreEqual("From", model.CityPoints[0].Placeholder);
            Assert.AreEqual("To", model.CityPoints[1].Placeholder);
            Assert.AreEqual(null, model.CityPoints[0].CityName);
            Assert.AreEqual(null, model.CityPoints[1].CityName);
            Assert.AreEqual(null, model.CityPoints[0].CityId);
            Assert.AreEqual(null, model.CityPoints[1].CityId);
        }
Пример #5
0
 /// <summary>
 /// Fills the AddRoadModel.
 /// </summary>
 /// <param name="manager">The ITranslationManager manager.</param>
 /// <param name="userLanguages">The user languages string.</param>
 /// <returns>The <see cref="AddRoadModel"/> with default placeholders.</returns>
 public static AddRoadModel FillAddRoadModel(IRoadsService client, AddRoadModel model, ITranslationManager manager, string userLanguages)
 {
     int searchingDepth = client.GetSearchingDepth();
     model.SearchingDepth = searchingDepth;
     model.CityPoints = new List<City>
     {
         new City
         {
             Placeholder =
                 manager.GetLabelTranslation("ARS1_Placeholder_From",
                     CultureHelper.GetCulture(userLanguages))
         },
         new City
         {
             Placeholder =
                 manager.GetLabelTranslation("ARS1_Placeholder_To",
                     CultureHelper.GetCulture(userLanguages))
         }
     };
     return model;
 }
Пример #6
0
        /// <summary>
        /// Check if AddRoadModel is valid.
        /// </summary>
        /// <param name="model">The model AddRoadModel.</param>
        /// <returns>If model is valid return true.</returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static bool CheckIfAddRoadModelValid(ref AddRoadModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (model.CityPoints == null)
            {
                throw new ArgumentNullException("model.CityPoints");
            }

            if (!model.CityPoints.Exists(m => m.CityId == null || m.CityName == null))
            {
                return true;
            }

            return false;
        }
Пример #7
0
        public ActionResult AddRoad(AddRoadModel model, List<City> сityPoints)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (сityPoints == null)
            {
                throw new ArgumentNullException("сityPoints");
            }

            model.CityPoints = сityPoints;

            if (!RoadHelper.CheckIfAddRoadModelValid(ref model))
            {
                TempData["SubmitFail"] = true;
                return RedirectToAction("AddRoad", "Roads");
            }
            if (Session != null)
            {
                Session["сityPoints"] = сityPoints;
            }

            return RedirectToAction("AddRoadStepTwo", "Roads");
        }