public void AssertTest(ITownRepository repository, ITown town) { viewModel.InitializeTownList(repository, town); Assert.IsNotNull(viewModel.CityList); Assert.IsNotNull(viewModel.DistrictList); Assert.IsNotNull(viewModel.TownList); if (town == null) { Assert.IsNull(viewModel.CityName); Assert.IsNull(viewModel.DistrictName); Assert.IsNull(viewModel.TownName); Assert.AreEqual(viewModel.CityList.Count, service.QueryCount()); Assert.AreEqual(viewModel.DistrictList.Count, 0); Assert.AreEqual(viewModel.TownList.Count, 0); } else { Assert.IsNotNull(viewModel.CityList); Assert.IsNotNull(viewModel.DistrictList); Assert.IsNotNull(viewModel.TownList); Assert.AreEqual(viewModel.CityName, town.CityName); Assert.AreEqual(viewModel.DistrictName, town.DistrictName); Assert.AreEqual(viewModel.TownName, town.TownName); viewModel.AssertRegionList(towns, town); } }
public ViewResult Region() { RegionViewModel viewModel = TempData["RegionViewModel"] as RegionViewModel; if (viewModel == null || viewModel.CityName == null) { List <Town> townList = townRepository.GetAllList(); Town town = (townList.Count > 0) ? townList.First() : null; viewModel = new RegionViewModel("addTown"); viewModel.InitializeTownList(townRepository, town); viewModel.InitializeRegionList(regionRepository, town); } else { viewModel.InitializeTownList(townRepository, viewModel); viewModel.InitializeRegionList(regionRepository, viewModel); } return(View(viewModel)); }