Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>

        public async Task <CountriesIteration> GetCountriesIterationByRegionAsync(string Id)
        {
            await InitAsync();

            CountriesIteration retour = new CountriesIteration();

            retour.countries       = new List <CountryModel>();
            retour.finalItemsCount = 0;
            retour.iterationKey    = String.Empty;
            if (!String.IsNullOrEmpty(Id))
            {
                String idToLower = Id.ToLower();
                foreach (String iterKey in _countriesMap.Keys)
                {
                    CountriesIteration countriesIteration = _countriesMap[iterKey];
                    if (countriesIteration.countries != null)
                    {
                        IEnumerable <CountryModel> countriesinRegion = from countryCandidate in countriesIteration.countries
                                                                       where (countryCandidate.region != null && idToLower.CompareTo(countryCandidate.region.ToLower()) == 0)
                                                                       select countryCandidate;

                        foreach (CountryModel countryIterator in countriesinRegion)
                        {
                            retour.countries.Add(countryIterator);
                        }
                    }
                }
                retour.finalItemsCount = retour.countries.Count;
            }
            return(retour);
        }
Пример #2
0
        public async Task Test_BufferedCountriesIterationRepository_GetCountrieIterationAsync_Return_Null_When_Called_With_Unexisting_String()
        {
            BufferedCountriesIterationRepository repo = new BufferedCountriesIterationRepository(new HRStubCountriesGetter());
            CountriesIteration retour = await repo.GetCountrieIterationAsync("ZZZZZ");

            Assert.IsNull(retour);
        }
Пример #3
0
        /// <summary>
        /// Get a specific countryIteration containing Countries filterd by alpha3Code.
        /// Based on the CountryService
        /// 1- If CountryService is available return result
        /// 2- Else throw Exception.
        /// </summary>
        /// <param name="alpha3Code">a Country Alpha3Code. e.g : 'FRA' foir France.</param>
        /// <returns>The countryIteration with the corresponding Alpha3Code Country if exists.</returns>
        public async Task <CountriesIteration> GetCountriesIterationByAlpha3CodeAsync(string alpha3Code)
        {
            //1-
            if (_countryService != null)
            {
                //Do not catch Exception
                CountryModel country = await _countryService.GetCountryByAlpha3CodeAsync(alpha3Code);

                CountriesIteration retour = new CountriesIteration();
                retour.countries = new List <CountryModel>();
                if (country != null)
                {
                    retour.countries.Add(country);
                    retour.finalItemsCount = 1;
                }
                else
                {
                    retour.finalItemsCount = 0;
                }
                retour.iterationKey = String.Empty;
                return(retour);
            }
            else
            {
                //2-
                throw new Exception(HRCountriesServicesSolution.Constant.COUNTRIESITERATION.COUNTRIESITERATION_SERVICE_ERROR_DESCRIPTION);
            }
        }
Пример #4
0
        private async Task <bool> InitAsync()
        {
            if (_countries == null)
            {
                //Chargement des pays :
                String countriesFileText = await _contentGetter.GetCountriesData();

                lock (_locker)
                {
                    _countries = JsonConvert.DeserializeObject <List <CountryModel> >(countriesFileText);
                }
                String boundariesFileText = await _contentGetter.GetBoundariesData();

                lock (_locker)
                {
                    FeatureCollection fc = JsonConvert.DeserializeObject <FeatureCollection>(boundariesFileText);
                    //La première itération avec une clé vide ne renvoi pas de pays mais l'id de la prochaine itération.
                    CountriesIteration ct = new CountriesIteration();
                    ct.iterationKey    = "1";
                    ct.finalItemsCount = _countries.Count;
                    _countriesMap.Add("", ct);
                    //La seconde itération renvoi les 20 premiers pays
                    ct = new CountriesIteration();
                    ct.iterationKey    = "2";
                    ct.finalItemsCount = _countries.Count;
                    ct.countries       = new List <CountryModel>();
                    for (int i = 0; i < 19; i++)
                    {
                        ct.countries.Add(_countries[i]);
                    }
                    _countriesMap.Add("1", ct);

                    //La seconde itération renvoi les 100 pays suivants
                    ct = new CountriesIteration();
                    ct.iterationKey    = "3";
                    ct.finalItemsCount = _countries.Count;
                    ct.countries       = new List <CountryModel>();
                    for (int i = 19; i < 120; i++)
                    {
                        ct.countries.Add(_countries[i]);
                    }
                    _countriesMap.Add("2", ct);

                    //La dernière itération renvoi  le reste.
                    ct = new CountriesIteration();
                    ct.finalItemsCount = _countries.Count;
                    ct.iterationKey    = "";
                    ct.countries       = new List <CountryModel>();
                    for (int i = 120; i < ct.finalItemsCount; i++)
                    {
                        ct.countries.Add(_countries[i]);
                    }
                    _countriesMap.Add("3", ct);
                }
            }
            return(true);
        }
Пример #5
0
        public async Task Test_BufferedCountriesIterationRepository_GetCountriesIterationByRegionAsync_Return_Null_When_Called_With_Unexisting_Region()
        {
            BufferedCountriesIterationRepository repo = new BufferedCountriesIterationRepository(new HRStubCountriesGetter());
            CountriesIteration retour = await repo.GetCountriesIterationByRegionAsync("ZZZZZZ");

            Assert.AreEqual("", retour.iterationKey);
            Assert.IsTrue(retour.finalItemsCount == 0);
            Assert.IsNotNull(retour.countries);
            Assert.IsTrue(retour.countries.Count == 0);
        }
Пример #6
0
        public async Task Test_BufferedCountriesIterationRepository_GetCountrieIterationAsync_Return_Iteration2_When_Called_With_2()
        {
            BufferedCountriesIterationRepository repo = new BufferedCountriesIterationRepository(new HRStubCountriesGetter());
            CountriesIteration retour = await repo.GetCountrieIterationAsync("2");

            Assert.AreEqual("3", retour.iterationKey);
            Assert.AreEqual(250, retour.finalItemsCount);
            Assert.IsNotNull(retour.countries);
            Assert.AreEqual(101, retour.countries.Count);
        }
        public async Task TestCountriesITerationService_GetCountriesIterationByAlpha3CodeAsync_Return_Empty_When_Called_With_Unexisting_Code()
        {
            BufferedCountriesIterationRepository repo = new BufferedCountriesIterationRepository(new HRStubCountriesGetter());
            CountriesServiceFRAStub   countryService  = new CountriesServiceFRAStub();
            CountriesIterationService service         = new CountriesIterationService(countryService, repo);
            CountriesIteration        ci = await service.GetCountriesIterationByAlpha3CodeAsync("ZZZ");

            Assert.IsNotNull(ci);
            Assert.AreEqual("", ci.iterationKey);
            Assert.AreEqual(0, ci.countries.Count);
        }
Пример #8
0
        public async Task Test_BufferedCountriesIterationRepository_GetCountrieIterationAsync_Return_FirstIteration_When_Called_With_Empty_String()
        {
            BufferedCountriesIterationRepository repo = new BufferedCountriesIterationRepository(new HRStubCountriesGetter());
            CountriesIteration retour = await repo.GetCountrieIterationAsync("");

            Assert.IsNotNull(retour);
            //Test de la première itération
            Assert.AreEqual("1", retour.iterationKey);
            Assert.AreEqual(250, retour.finalItemsCount);
            Assert.IsNull(retour.countries);
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        public leGrosStub()
        {
            if (__countries == null)
            {
                //Chargement des pays :
                string path           = HttpContext.Current.Server.MapPath("~/App_Data/allCountries.json");
                string boundariesPath = HttpContext.Current.Server.MapPath("~/App_Data/Boundaries.json");
                __countries = JsonConvert.DeserializeObject <List <CountryModel> >(File.ReadAllText(path));
                FeatureCollection fc = JsonConvert.DeserializeObject <FeatureCollection>(File.ReadAllText(boundariesPath));
            }
            //La première itération avec une clé vide ne renvoi pas de pays mais l'id de la prochaine itération.
            CountriesIteration ct = new CountriesIteration();

            ct.iterationKey    = "1";
            ct.finalItemsCount = __countries.Count;
            __data.Add("", ct);

            //La seconde itération renvoi les 20 premiers pays
            ct = new CountriesIteration();
            ct.iterationKey    = "2";
            ct.finalItemsCount = __countries.Count;
            ct.countries       = new List <CountryModel>();
            for (int i = 0; i < 19; i++)
            {
                ct.countries.Add(__countries[i]);
                //ct.countries.Add(new Country { alpha3Code = "AFG", name = "Afghanistan", capital = "Kabuuul", flag = "https://restcountries.eu/data/afg.svg", latlng = new float[2] { 33.0f, 65.0f } });
            }
            __data.Add("1", ct);

            //La seconde itération renvoi les 100 pays suivants
            ct = new CountriesIteration();
            ct.iterationKey    = "3";
            ct.finalItemsCount = __countries.Count;
            ct.countries       = new List <CountryModel>();
            for (int i = 19; i < 120; i++)
            {
                ct.countries.Add(__countries[i]);
            }
            __data.Add("2", ct);

            //La dernière itération renvoi  le reste.
            ct = new CountriesIteration();
            ct.finalItemsCount = __countries.Count;
            ct.iterationKey    = "";
            ct.countries       = new List <CountryModel>();
            for (int i = 120; i < ct.finalItemsCount; i++)
            {
                ct.countries.Add(__countries[i]);
            }

            __data.Add("3", ct);
        }
Пример #10
0
        //!HArd code à reprendre.
        /// <summary>
        ///
        /// </summary>
        public CountriesStub()
        {
            if (__countries == null)
            {
                //Chargement des pays :
                string path = HttpContext.Current.Server.MapPath("~/App_Data/allCountries.json");
                __countries = JsonConvert.DeserializeObject <List <CountryModel> >(File.ReadAllText(path));
            }


            //La première itération avec une clé vide ne renvoi pas de pays mais l'id de la prochaine itération.
            CountriesIteration ct = new CountriesIteration();

            ct.iterationKey    = "1";
            ct.finalItemsCount = __countries.Count;
            __data.Add("", ct);

            //La seconde itération renvoi les 20 premiers pays
            ct = new CountriesIteration();
            ct.iterationKey    = "2";
            ct.finalItemsCount = __countries.Count;
            ct.countries       = new List <CountryModel>();
            for (int i = 0; i < 19; i++)
            {
                ct.countries.Add(__countries[i]);
            }
            __data.Add("1", ct);

            //La seconde itération renvoi les 100 pays suivants
            ct = new CountriesIteration();
            ct.iterationKey    = "3";
            ct.finalItemsCount = __countries.Count;
            ct.countries       = new List <CountryModel>();
            for (int i = 19; i < 120; i++)
            {
                ct.countries.Add(__countries[i]);
            }
            __data.Add("2", ct);

            //La dernière itération renvoi  le reste.
            ct = new CountriesIteration();
            ct.finalItemsCount = __countries.Count;
            ct.iterationKey    = "";
            ct.countries       = new List <CountryModel>();
            for (int i = 120; i < ct.finalItemsCount; i++)
            {
                ct.countries.Add(__countries[i]);
            }
            __data.Add("3", ct);
        }
Пример #11
0
        public async Task Test_BufferedCountriesIterationRepository_GetCountriesIterationByRegionAsync_Return_AllEuropean_Countries_When_Called_With_Europe()
        {
            BufferedCountriesIterationRepository repo = new BufferedCountriesIterationRepository(new HRStubCountriesGetter());
            CountriesIteration retour = await repo.GetCountriesIterationByRegionAsync("Europe");

            Assert.AreEqual("", retour.iterationKey);
            Assert.IsTrue(retour.finalItemsCount > 0);
            Assert.IsNotNull(retour.countries);
            Assert.IsTrue(retour.countries.Count > 0);
            foreach (CountryModel iter in retour.countries)
            {
                Assert.AreEqual("Europe", iter.region);
            }
        }