Ejemplo n.º 1
0
        public async Task <IActionResult> SelectCity(string Country)
        {
            var topcitiesDataString = await GetAllCities.LoadAllCitiesData();

            var citiesList           = JsonConvert.DeserializeObject <List <CityInfoModel> >(topcitiesDataString);
            var topCitiesFromCountry = citiesList.Where(city => city.Country.ID == Country);

            if (topCitiesFromCountry.Count() == 0)
            {
                //return city search view
                //get admin area list

                /*
                 * string url = $"http://dataservice.accuweather.com/locations/v1/adminareas/{ Country }?apikey=KAsv18xGJd2pRClNCSKaDLR4NOx9HCPM";
                 * var adminAreasData = await CallApiEndPoint.LoadDataFromGivenUrl(url);
                 * var adminAreaList = JsonConvert.DeserializeObject<List<AdminAreaModel>>(adminAreasData);*/
                CitySearchModel csm = new CitySearchModel();
                csm.CountryCode = Country;

                return(View("CitySearch", csm));
            }
            else
            {
                //return available cities
                List <SelectListItem> cityListToRender = topCitiesFromCountry.Select(city => new SelectListItem
                {
                    Text  = city.EnglishName,
                    Value = city.Key
                }).ToList();
                CityViewModel cityvm = new CityViewModel();
                cityvm.CitiesList = cityListToRender;

                return(View(cityvm));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get()
        {
            var query  = new GetAllCities();
            var result = await SendRequest <IGetAllCities, IGetAllCitiesResult>(query);

            return(Ok(result));
        }
        public void GetAllCities_Action_Success()
        {
            // Arrange
            var fakeResponse = new GenericServiceResponse <IEnumerable <CityDto> >
            {
                Result = TestHelper.CityDtos()
            };

            mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable();
            mockClientServicesProvider.Setup(x => x.CityService.GetAllCities()).Returns(fakeResponse).Verifiable();

            var viewModel = new GenericListViewModel <CityDto>();

            var action = new GetAllCities <GenericListViewModel <CityDto> >(mockClientServicesProvider.Object)
            {
                OnComplete = model => viewModel = model
            };

            // Act
            var result = action.Invoke();

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(GenericListViewModel <CityDto>));
            Assert.IsNotNull(result.Notifications);
            Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection));
            Assert.IsTrue(result.Notifications.Count() == 0);
            Assert.IsFalse(result.HasErrors);
            Assert.IsNotNull(result.Items);
            Assert.IsInstanceOfType(result.Items, typeof(IEnumerable <CityDto>));
            Assert.IsTrue(result.Items.ToList().Count() == TestHelper.CityDtos().Count());
        }