コード例 #1
0
        /// <summary>
        /// Loads supported city list from file.
        /// </summary>
        private void LoadCountryList()
        {
            var jsonFileReader = new JsonFileReader <IList <Country> >("Weather.Data.", "country.list.json");

            jsonFileReader.Read();
            _provider = new CountryProvider(jsonFileReader.Result.AsQueryable());
        }
コード例 #2
0
        public void Test_Get_By_Id()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <DataBaseContext>().UseSqlite(connection).Options;

            using (var context = new DataBaseContext(options))
            {
                context.Database.EnsureCreated();
            }

            using (var context = new DataBaseContext(options))
            {
                context.Countries.Add(new Country {
                    Id = 1, Description = "First country", Name = "Colombia"
                });
                context.SaveChanges();
            }

            using (var context = new DataBaseContext(options))
            {
                var provider = new CountryProvider(context);
                var country  = provider.Get(1);

                Assert.AreEqual("Colombia", country.Name);
            }
        }
コード例 #3
0
        public void CheckAllCulture()
        {
            ICountryProvider countryProvider = new CountryProvider();

            CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

            foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
            {
                var countryInfo = countryProvider.GetCountry(countryCode);
                if (countryInfo == null)
                {
                    continue;
                }

                var expectedLanguages = countryInfo.Translations.Select(x => x.LanguageCode).ToList();
                foreach (var culture in cultures)
                {
                    bool expectResult = false;
                    if (Enum.TryParse(culture.TwoLetterISOLanguageName, true, out LanguageCode code) == true)
                    {
                        expectResult = expectedLanguages.Any(x => x == code);
                    }

                    var translatedCountryName = countryProvider.GetCountryTranslatedName(countryCode, culture);
                    if (expectResult == true && String.IsNullOrWhiteSpace(translatedCountryName) == true)
                    {
                        Assert.Fail($"A result was expected but there was no translated country name found for {countryCode} and culture {culture.Name} (language {culture.TwoLetterISOLanguageName})");
                    }
                }
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var exportDirectory = "export";

            if (!Directory.Exists(exportDirectory))
            {
                Directory.CreateDirectory(exportDirectory);
            }

            var jsonSerializerOptions = new JsonSerializerOptions
            {
                Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                Converters           =
                {
                    new JsonStringEnumConverterWithAttributeSupport(null, true, true, true, true)
                },
                WriteIndented = true
            };

            var countryProvider = new CountryProvider();
            var countries       = countryProvider.GetCountries();

            foreach (var country in countries)
            {
                var jsonData = JsonSerializer.SerializeToUtf8Bytes(country, jsonSerializerOptions);
                File.WriteAllBytesAsync($"{exportDirectory}/{country.Alpha2Code}.json", jsonData).GetAwaiter().GetResult();
            }

            Console.WriteLine("Json export done");
        }
コード例 #5
0
        private AirPackageModel GetViewModel(int id, string tranMode, bool isPost = false)
        {
            ///tranMode = "N" , "U", "L", "V"

            if (id != 0 && isPost == false)
            {
                _modObj = _provider.GetDetails(id);
            }

            _modObj.EffectiveFrom = DateTime.Now;
            _modObj.ExpireOn      = DateTime.Now.AddDays(1);


            _modObj.ddlCountryList = CountryProvider.GetSelectListOptions();
            _modObj.ddlCityList    = CoreCityProvider.GetSelectListOptions(_modObj.CountryId);
            _modObj.ddlDuration    = AirPackageProvider.GetSelectListOptionDuration();
            _modObj.ddlZoneList    = new SelectList(_provider.GetZoneList(), "ZoneId", "ZoneValue");
            _provider.GetPackageGroupNameDdl(_modObj);



            //  _modObj.packageDetail = new ATLTravelPortal.Repository.PackageProvider().GetDetail(id.ToString());
            SetUpFormParams(tranMode);
            return(_modObj);
        }
コード例 #6
0
        public void OneTimeSetUp()
        {
            var mockIdGenerator = new Mock <IIdGenerator>();

            mockIdGenerator.Setup(x => x.Generate()).Returns(Id);

            _sut = new CountryProvider(mockIdGenerator.Object);
        }
コード例 #7
0
        public void GetCountryTranslatedName()
        {
            ICountryProvider countryProvider = new CountryProvider();

            var translatedCountryName = countryProvider.GetCountryTranslatedName(Alpha2Code.DE, LanguageCode.EN);

            Assert.AreEqual("Germany", translatedCountryName);
        }
コード例 #8
0
        public void GetCountryByNameConsiderTranslation(string countryName)
        {
            ICountryProvider countryProvider = new CountryProvider();

            var countryInfo = countryProvider.GetCountryByNameConsiderTranslation(countryName);

            Assert.AreEqual(Alpha2Code.AT, countryInfo.Alpha2Code);
        }
コード例 #9
0
        public ActionResult Create()
        {
            AirPackageGroupModel _model = new AirPackageGroupModel();

            _provider.getddl(_model);
            _model.ddlCountryList = CountryProvider.GetSelectListOptions();
            _model.ddlZoneList    = new SelectList(_provider.GetZoneList(), "ZoneId", "ZoneValue");
            return(View(_model));
        }
コード例 #10
0
        public CountryProviderTests()
        {
            _handlerMock = new Mock <HttpMessageHandler>();
            _client      = new HttpClient(_handlerMock.Object)
            {
                BaseAddress = new Uri("http://somefakeUrl")
            };

            _classUnderTest = new CountryProvider(_client);
        }
コード例 #11
0
ファイル: UsersControl.cs プロジェクト: jy4618272/Common
 private void SaveCountry()
 {
     if (CountryList != null)
     {
         if (m_CountryList.SelectedIndex == -1)
         {
             CountryProvider.InsertCountry(m_CountryList.Text);
         }
     }
 }
コード例 #12
0
        public void GetCountry(string countryCode)
        {
            ICountryProvider countryProvider = new CountryProvider();

            var countryInfo = countryProvider.GetCountry(countryCode);

            if (countryInfo == null)
            {
                Assert.Fail($"Cannot found countryCode: {countryCode}");
            }
        }
コード例 #13
0
        public void GetCountries()
        {
            ICountryProvider countryProvider = new CountryProvider();
            var countries = countryProvider.GetCountries();

            foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
            {
                if (countries.Any(x => x.Alpha2Code == countryCode) == false)
                {
                    Assert.Fail($"No country in all countries list for country code {countryCode}");
                }
            }
        }
コード例 #14
0
        public void GetCountries()
        {
            ICountryProvider countryProvider = new CountryProvider();
            var countries             = countryProvider.GetCountries();
            var availableCountryCodes = (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code));

            foreach (var countryCode in availableCountryCodes)
            {
                if (!countries.Any(x => x.Alpha2Code == countryCode))
                {
                    Assert.Fail($"Cannot found a CountryInfo for countryCode: {countryCode}");
                }
            }
        }
コード例 #15
0
        public void CheckTranslationsAvailableTest()
        {
            ICountryProvider countryProvider = new CountryProvider();

            foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
            {
                var countryInfo = countryProvider.GetCountry(countryCode);
                if (countryInfo == null)
                {
                    continue;
                }

                var translationCount = countryInfo.Translations.Length;
                Assert.IsTrue(translationCount > 5, $"missing translations {countryCode}");
            }
        }
コード例 #16
0
        public EmailService(IConfigProvider configProvider, IIndex <TokenSourceType, SecureAccessTokenSource> satIndex, CountryProvider countryProvider)
        {
            _configProvider  = configProvider;
            _countryProvider = countryProvider;

            _emailConfirmationTokenSource = satIndex[TokenSourceType.EmailConfirmation];
            _passwordResetTokenSource     = satIndex[TokenSourceType.PasswordReset];

            if (_configProvider.UseMailgun)
            {
                _mailgun = new MailgunService(_configProvider);
            }
            else
            {
                _smtp = new SmtpClient();
            }
        }
コード例 #17
0
        public void Init(int ownerId)
        {
            Id = ownerId;

            StatsManager.Init(Id, 0, _dbMob.Dex, 0, 0, _dbMob.Wis, _dbMob.Luc, def: _dbMob.Defense, res: _dbMob.Magic);
            LevelProvider.Init(Id, _dbMob.Level);
            HealthManager.Init(Id, _dbMob.HP, _dbMob.MP, _dbMob.SP, _dbMob.HP, _dbMob.MP, _dbMob.SP);
            BuffsManager.Init(Id);
            CountryProvider.Init(Id, _dbMob.Fraction);
            SpeedManager.Init(Id);
            AttackManager.Init(Id);
            SkillsManager.Init(Id, new Skill[0]);

            var x = new Random().NextFloat(_moveArea.X1, _moveArea.X2);
            var y = new Random().NextFloat(_moveArea.Y1, _moveArea.Y2);
            var z = new Random().NextFloat(_moveArea.Z1, _moveArea.Z2);

            MovementManager.Init(Id, x, y, z, 0, MoveMotion.Walk);

            AIManager.Init(Id,
                           _dbMob.AI,
                           _moveArea,
                           idleTime: _dbMob.NormalTime <= 0 ? 4000 : _dbMob.NormalTime,
                           idleSpeed: _dbMob.NormalStep,
                           chaseRange: _dbMob.ChaseRange,
                           chaseSpeed: _dbMob.ChaseStep,
                           chaseTime: _dbMob.ChaseTime,
                           isAttack1Enabled: _dbMob.AttackOk1 != 0,
                           isAttack2Enabled: _dbMob.AttackOk2 != 0,
                           isAttack3Enabled: _dbMob.AttackOk3 != 0,
                           attack1Range: _dbMob.AttackRange1,
                           attack2Range: _dbMob.AttackRange2,
                           attack3Range: _dbMob.AttackRange3,
                           attackType1: _dbMob.AttackType1,
                           attackType2: _dbMob.AttackType2,
                           attackType3: _dbMob.AttackType3,
                           attackAttrib1: _dbMob.AttackAttrib1,
                           attackAttrib2: _dbMob.AttackAttrib2,
                           attack1: _dbMob.Attack1 < 0 ? (ushort)(_dbMob.Attack1 + ushort.MaxValue) : (ushort)_dbMob.Attack1,
                           attack2: _dbMob.Attack2 < 0 ? (ushort)(_dbMob.Attack2 + ushort.MaxValue) : (ushort)_dbMob.Attack2,
                           attack3: _dbMob.Attack3 < 0 ? (ushort)(_dbMob.Attack3 + ushort.MaxValue) : (ushort)_dbMob.Attack3,
                           attackTime1: _dbMob.AttackTime1,
                           attackTime2: _dbMob.AttackTime2,
                           attackTime3: _dbMob.AttackTime3);
        }
コード例 #18
0
        public double Calculate(Customer customer, Provider provider, Order order)
        {
            if (!provider.Company.IsVAT)
            {
                return(order.Price);
            }

            if (CountryProvider == null)
            {
                throw new BussinessException("Not Specified CountryProvider");
            }
            if (VATGetter == null)
            {
                throw new BussinessException("Not Specified VATGetter");
            }

            var isCustomerEU  = CountryProvider.IsInEurope(customer.Country);
            var isProviderEU  = CountryProvider.IsInEurope(provider.Country);
            var customerVAT   = VATGetter.GetVAT(customer.Country);
            var providerVAT   = VATGetter.GetVAT(provider.Country);
            int?applicableVAT = null;

            if (customer.Country == provider.Country)
            {
                applicableVAT = customerVAT;
            }
            else
            {
                if (isCustomerEU &&
                    (customer.Company == null || customer.Company.IsVAT == false) &&
                    customer.Country != provider.Country)
                {
                    applicableVAT = providerVAT;
                }
            }
            if (applicableVAT != null)
            {
                return(order.Price + order.Price / 100 * applicableVAT.Value);
            }
            return(order.Price);
        }
コード例 #19
0
        public async Task CompareWithMledozeCountryProject()
        {
            using (var httpClient = new HttpClient())
            {
                var json = await httpClient.GetStringAsync("https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json");

                var items = JsonConvert.DeserializeObject <MledozeCountry[]>(json);

                ICountryProvider countryProvider = new CountryProvider();
                foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
                {
                    var countryInfo = countryProvider.GetCountry(countryCode);
                    Trace.WriteLine($"check {countryInfo.CommonName}");
                    if (countryInfo == null)
                    {
                        Assert.Fail($"countryInfo is null for {countryCode}");
                    }

                    var compareCountry = items.FirstOrDefault(o => o.Cca2.Equals(countryInfo.Alpha2Code.ToString()));
                    if (compareCountry == null)
                    {
                        Assert.Inconclusive(countryCode.ToString());
                        continue;
                    }

                    //TODO: Check how can check after change structure
                    //countryInfo.Currencies
                    //    .Should()
                    //    .BeEquivalentTo(compareCountry.Currencies.ChildrenToke.Name.ToArray(),
                    //    because: $"{countryCode} {string.Join(",", compareCountry.Currencies.Keys)}  {string.Join(",", countryInfo.Currencies)}");

                    Assert.AreEqual(compareCountry.Ccn3, countryInfo.NumericCode, $"wrong numeric code by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(compareCountry.Region, countryInfo.Region.ToString(), $"wrong region by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(this.AdaptMledozeSubRegion(compareCountry.Subregion), this.GetSubRegion(countryInfo.SubRegion), $"wrong subregion by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(compareCountry.Cca3, countryInfo.Alpha3Code.ToString(), $"wrong alpha 3 code by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(compareCountry.Name.Common, countryInfo.CommonName.ToString(), $"wrong common name by {countryCode} {countryInfo.CommonName}");
                }
            }
        }
コード例 #20
0
        public void DuplicateTranslationTest()
        {
            var missingCountries = new List <Alpha2Code>();

            ICountryProvider countryProvider = new CountryProvider();

            foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
            {
                var countryInfo = countryProvider.GetCountry(countryCode);
                if (countryInfo == null)
                {
                    missingCountries.Add(countryCode);
                    continue;
                }

                var duplicateTranslation = countryInfo.Translations.GroupBy(o => o.LanguageCode).Where(o => o.Count() > 1).Any();
                Assert.IsFalse(duplicateTranslation);
            }

            if (missingCountries.Count > 0)
            {
                Assert.Inconclusive(string.Join(",", missingCountries));
            }
        }
コード例 #21
0
        public async Task CompareWithMledozeCountryProject()
        {
            using (var httpClient = new HttpClient())
            {
                var json = await httpClient.GetStringAsync("https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json");

                var items = JsonConvert.DeserializeObject <MledozeCountry[]>(json);

                ICountryProvider countryProvider = new CountryProvider();
                foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
                {
                    var countryInfo = countryProvider.GetCountry(countryCode);
                    if (countryInfo == null)
                    {
                        Assert.Fail($"countryInfo is null for {countryCode}");
                    }

                    var compareCountry = items.FirstOrDefault(o => o.Cca2.Equals(countryInfo.Alpha2Code.ToString()));
                    if (compareCountry == null)
                    {
                        Assert.Inconclusive(countryCode.ToString());
                        continue;
                    }

                    countryInfo.Currencies
                    .Should()
                    .BeEquivalentTo(compareCountry.Currency,
                                    because: $"{countryCode} {string.Join(",", compareCountry.Currency)}  {string.Join(",", countryInfo.Currencies)}");

                    Assert.AreEqual(compareCountry.Ccn3, countryInfo.NumericCode, $"wrong numeric code by {countryCode}");
                    //Assert.AreEqual(countryInfo.Region.ToString(), compareCountry.Region, $"wrong region by {countryCode}");
                    Assert.AreEqual(compareCountry.Cca3, countryInfo.Alpha3Code.ToString(), $"wrong alpha 3 code by {countryCode}");
                    Assert.AreEqual(compareCountry.Name.Common, countryInfo.CommonName.ToString(), $"wrong common name by {countryCode}");
                }
            }
        }
コード例 #22
0
 public HomeController()
 {
     this._countryProvider = new CountryProvider();
 }
コード例 #23
0
 public RegionController(CountryProvider countryProvider, RegionProvider regionProvider, IMapper mapper)
 {
     this.mapper          = mapper;
     this.countryProvider = countryProvider;
     this.regionProvider  = regionProvider;
 }
コード例 #24
0
ファイル: PreviewPage.cs プロジェクト: Adel-dz/Hub
        void ModifyPalceCountry()
        {
            ListViewItem lvi = m_lvData.SelectedItems[0];
            var          p   = lvi.Tag as Places.Place;

            if (p != null)
            {
                using (var dp = new CountryProvider(this))
                {
                    Predicate <IDataRow> compPlace = x => x == p;

                    using (var dlg = new Countries.ChooseCountryDialog(dp))
                    {
                        if (p.CountryID != 0)
                        {
                            dp.Connect();

                            foreach (Countries.Country ctry in dp.Enumerate())
                            {
                                if (ctry.ID == p.CountryID)
                                {
                                    dlg.SelectedCountry = ctry;
                                    break;
                                }
                            }
                        }

                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            Countries.Country newCtry = dlg.SelectedCountry;
                            var place = new Places.Place(p.ID, p.Name, newCtry.ID);

                            int ndxPlace = m_modifiedPlaces.FindIndex(compPlace);

                            if (ndxPlace >= 0)
                            {
                                m_modifiedPlaces[ndxPlace] = place;
                            }
                            else
                            {
                                m_modifiedPlaces.Add(place);
                            }


                            ndxPlace = m_impData[TablesID.PLACE].FindIndex(compPlace);
                            m_impData[TablesID.PLACE][ndxPlace] = place;

                            const int NDX_COUNTRY = 2;
                            lvi.SubItems[NDX_COUNTRY].Text = newCtry.ID.ToString();
                            lvi.Tag = place;

                            if (m_boldFont == null)
                            {
                                m_boldFont = new Font(lvi.Font, FontStyle.Bold);
                            }

                            lvi.Font       = m_boldFont;
                            lvi.ImageIndex = -1;
                        }
                    }
                }
            }
        }