Example #1
0
 public ActionResult AddTown(RegionViewModel viewModel)
 {
     Town addConditions = viewModel.AddTownConditions;
     if (!addConditions.IsAddConditionsValid())
     {
         TempData["error"] = "输入有误!城市、区域、镇区都不能为空。";
         return RedirectToAction("Region");
     }
     TownOperationService service = new TownOperationService(townRepository, addConditions);
     service.SaveOneTown();
     TempData["success"] = "增加镇街:" + addConditions.GetAddConditionsInfo() + "成功";
     TempData["RegionViewModel"] = new RegionViewModel("addTown")
     {
         CityName = addConditions.CityName,
         DistrictName = addConditions.DistrictName,
         TownName = addConditions.TownName,
         RegionName = viewModel.RegionName
     };
     return RedirectToAction("Region");
 }
Example #2
0
 public void TestSaveAndDeleteTown_AddSuccess_DeleteFail()
 {
     Assert.AreEqual(repository.Object.Count(), 1);
     TownOperationService service = new TownOperationService(repository.Object,
         "Foshan", "Nanhai ", "Guicheng ");
     service.SaveOneTown();
     Assert.AreEqual(repository.Object.Count(), 2);
     service = new TownOperationService(repository.Object,
         "Foshan", "Nanhai", "Dali");
     Assert.IsFalse(service.DeleteOneTown());
     Assert.AreEqual(repository.Object.Count(), 2);
 }
Example #3
0
 public void TestSaveAndDeleteTown_AddFail_DeleteSuccess()
 {
     Assert.AreEqual(repository.Object.Count(), 1);
     TownOperationService service = new TownOperationService(repository.Object,
         "Foshan", "Chancheng ", "Zhangcha ");
     service.SaveOneTown();
     Assert.AreEqual(repository.Object.Count(), 1, "Add town success! But it's expected to be failed!");
     service = new TownOperationService(repository.Object,
         "Foshan", "Chancheng ", "Zhangcha ");
     Assert.IsTrue(service.DeleteOneTown());
     Assert.AreEqual(repository.Object.Count(), 0);
 }
Example #4
0
 public void TestSaveTown_Success()
 {
     Assert.AreEqual(repository.Object.Count(), 1);
     TownOperationService service = new TownOperationService(repository.Object,
         "Foshan", "Nanhai", "Guicheng");
     service.SaveOneTown();
     Assert.AreEqual(repository.Object.Count(), 2);
 }
Example #5
0
 public void TestSaveTown_Fail()
 {
     Assert.AreEqual(repository.Object.Count(), 1);
     TownOperationService service = new TownOperationService(repository.Object,
         "Foshan", "Chancheng", "Zhangcha");
     service.SaveOneTown();
     Assert.AreEqual(repository.Object.Count(), 1);
 }
Example #6
0
 public void TestSaveAndDeleteTown_AddSuccess_DeleteSucess()
 {
     Assert.AreEqual(repository.Object.Count(), 1, "original");
     TownOperationService service = new TownOperationService(repository.Object,
         "Foshan", "Nanhai ", "Guicheng ");
     service.SaveOneTown();
     Assert.AreEqual(repository.Object.Count(), 2, "save");
     repository.MockRepositoryDeleteItems<Town, ITownRepository>();
     service = new TownOperationService(repository.Object,
         "Foshan", "Nanhai", "Guicheng");
     Assert.IsTrue(service.DeleteOneTown());
     Assert.AreEqual(repository.Object.Count(), 1, "delete");
 }
 public void TestAddTown(int cityId, int districtId, int townId)
 {
     service = new TownOperationService(repository,
         "C-" + cityId, "D-" + districtId, "T-" + townId);
     service.SaveOneTown();
 }