Ejemplo n.º 1
0
 public static void AssertRegionList(this ITownDefViewModel viewModel,
     IEnumerable<Town> towns, ITown town)
 {
     QueryNamesService service = new QueryDistinctCityNamesService(towns);
     Assert.AreEqual(viewModel.CityList.Count, service.QueryCount());
     SelectListItem cityItem = viewModel.CityList.FirstOrDefault(x => x.Text == town.CityName);
     if (cityItem != null)
     {
         Assert.IsTrue(cityItem.Selected);
     }
     service = new QueryDistinctDistrictNamesService(towns, town.CityName);
     Assert.AreEqual(viewModel.DistrictList.Count, service.QueryCount());
     SelectListItem districtItem = viewModel.DistrictList.FirstOrDefault(x => x.Text == town.DistrictName);
     if (districtItem != null)
     {
         Assert.IsTrue(districtItem.Selected);
     }
     service = new QueryDistinctTownNamesService(towns, town.CityName, town.DistrictName);
     Assert.AreEqual(viewModel.TownList.Count, service.QueryCount());
     SelectListItem townItem = viewModel.TownList.FirstOrDefault(x => x.Text == town.TownName);
     if (townItem != null)
     {
         Assert.IsTrue(townItem.Selected);
     }
 }
Ejemplo n.º 2
0
 public static void Initialize(this ITownDefViewModel viewModel, IEnumerable<Town> towns, ITown town)
 {
     QueryNamesService service = new QueryDistinctCityNamesService(towns);
     viewModel.CityList
             = service.Query().ToList().Select(
             x => new SelectListItem { Value = x, Text = x, Selected = x == town.CityName }).ToList();
     service = new QueryDistinctDistrictNamesService(towns, town.CityName);
     viewModel.DistrictList
         = service.Query().ToList().Select(
             x => new SelectListItem { Value = x, Text = x, Selected = x == town.DistrictName }).ToList();
     service = new QueryDistinctTownNamesService(towns, town.CityName, town.DistrictName);
     viewModel.TownList
         = service.Query().ToList().Select(
             x => new SelectListItem { Value = x, Text = x, Selected = x == town.TownName }).ToList();
 }
Ejemplo n.º 3
0
        public void AssertTest(int cityId = 0, int districtId = 0, int townId = 0)
        {
            viewResult = controller.Query();
            viewModel = viewResult.Model as ENodebQueryViewModel;
            IEnumerable<ENodeb> resultENodebs = new List<ENodeb>();

            SetViewModelParameters(cityId, districtId, townId);
            Assert.IsNotNull(viewModel);
            if (viewModel == null) return;
            Assert.IsNotNull(viewModel.CityList);
            Assert.IsNotNull(viewModel.DistrictList);
            Assert.IsNotNull(viewModel.TownList);
            QueryNamesService service = new QueryDistinctCityNamesService(towns);
            Assert.AreEqual(viewModel.CityList.Count, service.QueryCount());
            if (cityId == 0)
            {
                Assert.IsNull(viewModel.CityName);
                Assert.IsNull(viewModel.DistrictName);
                Assert.IsNull(viewModel.TownName);
                Assert.AreEqual(viewModel.DistrictList.Count, 0);
                Assert.AreEqual(viewModel.TownList.Count, 0);
                Assert.IsNull(viewModel.ENodebs);
            }
            else
            {
                IEnumerable<Town> matchedCityTowns = towns.Where(x => x.CityName == viewModel.CityName);
                if (matchedCityTowns.Any())
                {
                    service = new QueryDistinctDistrictNamesService(towns, viewModel.CityName);
                    Assert.AreEqual(viewModel.DistrictList.Count, service.QueryCount(),
                        "Total towns are not matched!");
                    if (districtId == 0)
                    {
                        Assert.IsNull(viewModel.DistrictName);
                        Assert.IsNull(viewModel.TownName);
                        Assert.AreEqual(viewModel.TownList.Count, 0);
                        resultENodebs = from e in eNodebs
                            join t in matchedCityTowns on e.TownId equals t.Id
                            select e;
                    }
                    else
                    {
                        Assert.IsNotNull(viewModel.DistrictName);
                        Assert.AreEqual(viewModel.DistrictName, "District" + districtId);
                        IEnumerable<Town> matchedDistrictTowns = matchedCityTowns.Where(
                            x => x.DistrictName == viewModel.DistrictName);
                        if (matchedDistrictTowns.Any())
                        {
                            service = new QueryDistinctTownNamesService(
                                towns, viewModel.CityName, viewModel.DistrictName);
                            Assert.AreEqual(viewModel.TownList.Count, service.QueryCount(),
                                "Towns matched district are not matched!");
                            if (townId == 0)
                            {
                                Assert.IsNull(viewModel.TownName);
                                resultENodebs = from e in eNodebs
                                    join t in matchedDistrictTowns on e.TownId equals t.Id
                                    select e;
                            }
                            else
                            {
                                Assert.IsNotNull(viewModel.TownName);
                                Assert.AreEqual(viewModel.TownName, "Town" + townId);
                                Town matchedTown = matchedDistrictTowns.FirstOrDefault(x => x.TownName == viewModel.TownName);
                                if (matchedTown != null)
                                {
                                    resultENodebs = eNodebs.Where(x => x.TownId == matchedTown.Id);
                                }
                            }
                        }
                    }
                    AssertENodebs(resultENodebs);
                }
                else
                {
                    Assert.IsNull(viewModel.DistrictName);
                    Assert.IsNull(viewModel.TownName);
                    Assert.AreEqual(viewModel.DistrictList.Count, 0);
                    Assert.AreEqual(viewModel.TownList.Count, 0);
                    Assert.IsNull(viewModel.ENodebs);
                }
            }
        }
Ejemplo n.º 4
0
 public IEnumerable<string> GetTownList(string cityName, string districtName)
 {
     QueryNamesService service = new QueryDistinctTownNamesService(
         townRepository.GetAll(), cityName, districtName);
     return service.Query().ToList();
 }
Ejemplo n.º 5
0
        public void AssertInitialTown(string cityName = null, string districtName = null, string townName = null)
        {
            controller.TempData["RegionViewModel"] =
                (cityName == null && districtName == null && townName == null) ? null :
                new RegionViewModel("")
                {
                    CityName = cityName,
                    DistrictName = districtName,
                    TownName = townName
                };
            RegionViewModel initialViewModel = controller.TempData["RegionViewModel"] as RegionViewModel;
            townRepository.Setup(x => x.GetAll()).Returns(towns.AsQueryable());
            townRepository.Setup(x => x.GetAllList()).Returns(townRepository.Object.GetAll().ToList());
            townRepository.Setup(x => x.Count()).Returns(townRepository.Object.GetAll().Count());
            ViewResult result = controller.Region();
            RegionViewModel viewModel = result.Model as RegionViewModel;
            Assert.IsNotNull(viewModel);
            Assert.IsNotNull(viewModel.CityList);
            Assert.IsNotNull(viewModel.DistrictList);
            Assert.IsNotNull(viewModel.TownList);

            AssertNames(initialViewModel, viewModel);
            QueryNamesService namesService = new QueryDistinctCityNamesService(towns);
            Assert.AreEqual(viewModel.CityList.Count, namesService.QueryCount());
            namesService = new QueryDistinctDistrictNamesService(towns, viewModel.CityName);
            Assert.AreEqual(viewModel.DistrictList.Count, namesService.QueryCount());
            namesService = new QueryDistinctTownNamesService(towns, viewModel.CityName, viewModel.DistrictName);
            Assert.AreEqual(viewModel.TownList.Count, namesService.QueryCount());
            AssertSelectedItems(viewModel);
        }