public void Test_CallingCode_Update() { var callingCode = new CallingCode() { DetachedState = DetachedState.Added, CallingCodeNumber = callingCodeNumberUpdate }; var validationResults = Get_Validation_Results(callingCode); Assert.AreEqual(expected: 0, actual: validationResults.Count); using (var entityManager = new CountriesEntityManager()) { entityManager.AddEntity <CallingCode>(callingCode); int updateCount = entityManager.SaveChanges(); Assert.AreNotEqual(notExpected: 0, actual: updateCount); } callingCode.CallingCodeNumber = callingCodeNumberUpdate2; using (var entityManager = new CountriesEntityManager()) { entityManager.Attach <CallingCode>(callingCode); int updateCount = entityManager.SaveChanges(); Assert.AreNotEqual(notExpected: 0, actual: updateCount); } using (var entityManager = new CountriesEntityManager()) { var callingCodeFromDb = entityManager.Set <CallingCode>() .Where(x => (x.Id == callingCode.Id)) .SingleOrDefault(); Assert.IsNotNull(callingCodeFromDb); Assert.AreEqual(expected: callingCodeNumberUpdate2, actual: callingCodeFromDb.CallingCodeNumber); } }
public void Test_CallingCode_Create() { var callingCode = new CallingCode() { DetachedState = DetachedState.Added, CallingCodeNumber = callingCodeNumberCreate }; var validationResults = Get_Validation_Results(callingCode); Assert.AreEqual(expected: 0, actual: validationResults.Count); using (var entityManager = new CountriesEntityManager()) { entityManager.AddEntity <CallingCode>(callingCode); int updateCount = entityManager.SaveChanges(); Assert.AreNotEqual(notExpected: 0, actual: updateCount); } using (var entityManager = new CountriesEntityManager()) { var dallingCodeFromDb = entityManager.Set <CallingCode>() .Where(x => (x.Id == callingCode.Id)) .SingleOrDefault(); Assert.IsNotNull(dallingCodeFromDb); Assert.AreEqual(expected: callingCode.ToCSVString(), actual: dallingCodeFromDb.ToCSVString()); // all entity properties must be virtual for this to work var proxy = dallingCodeFromDb as IEntityWithChangeTracker; Assert.IsNotNull(proxy); } }
private async void txtCountryCode_Focused(object sender, FocusEventArgs e) { var popPage = new CallingCode(); popPage.SelectionSucceeded += (s, arg) => { txtCountryCode.Text = "+" + arg.Code; }; txtCountryCode.Unfocus(); await Navigation.PushModalAsync(popPage); }
public override int GetHashCode() { int hashCode = 343986405; if (CallingCode != null) { hashCode += CallingCode.GetHashCode(); } if (Number != null) { hashCode += Number.GetHashCode(); } return(hashCode); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is V1PhoneNumber other && ((CallingCode == null && other.CallingCode == null) || (CallingCode?.Equals(other.CallingCode) == true)) && ((Number == null && other.Number == null) || (Number?.Equals(other.Number) == true))); }
public void Test_CallingCode_Validation() { var callingCode = new CallingCode(); callingCode.CallingCodeNumber = 1001; var validationResults = Get_Validation_Results(callingCode); Assert.IsTrue(validationResults.Count > 0); Assert.IsTrue(validationResults.Any( x => x.MemberNames.Any(y => string.Equals(y, "EntityKey", StringComparison.OrdinalIgnoreCase)))); Assert.IsTrue(validationResults.Any( x => x.MemberNames.Any(y => string.Equals(y, "Id", StringComparison.OrdinalIgnoreCase)))); Assert.IsTrue(validationResults.Any( x => x.MemberNames.Any(y => string.Equals(y, "CallingCodeNumber", StringComparison.OrdinalIgnoreCase)))); }
public async Task <ActionResult> PopulateDatabase() { if (this.context.Countries.Any() == false) { var httpClient = new HttpClient(); var countriesAsString = await httpClient.GetStringAsync("https://restcountries.eu/rest/v2/all"); var countriesAsJson = JsonConvert.DeserializeObject <List <CountryCreateApiBindingModel> >(countriesAsString); foreach (var countryCreateModel in countriesAsJson) { var country = new Country { Name = countryCreateModel.Name, Alpha2Code = countryCreateModel.Alpha2Code, Aplha3Code = countryCreateModel.Aplha3Code, Capital = countryCreateModel.Capital, Region = countryCreateModel.Region, SubRegion = countryCreateModel.SubRegion, Population = countryCreateModel.Population, Demonym = countryCreateModel.Demonym, Area = countryCreateModel.Area, Gini = countryCreateModel.Gini, NativeName = countryCreateModel.NativeName, NumericCode = countryCreateModel.NumericCode, FlagUrl = countryCreateModel.FlagUrl, Cioc = countryCreateModel.Cioc, }; foreach (var internetDomainAsString in countryCreateModel.Domains) { var internetDomain = new InternetDomain { Name = internetDomainAsString, Country = country }; this.context.InternetDomains.Add(internetDomain); } foreach (var callingCodeAsString in countryCreateModel.CallingCodes) { var callingCode = new CallingCode { Name = callingCodeAsString, CountryId = country.Id }; this.context.CallingCodes.Add(callingCode); } foreach (var altSpellingAsString in countryCreateModel.AlternativeSpellings) { var alternativeSpelling = new AlternativeSpelling { Name = altSpellingAsString, Country = country }; this.context.AlternativeSpellings.Add(alternativeSpelling); } if (countryCreateModel.Coordinates.Count == 2) { var coordinates = new Coordinates { Latitude = countryCreateModel.Coordinates[0], Longitude = countryCreateModel.Coordinates[1] }; country.Coordinates = coordinates; } else { var coordinates = new Coordinates { Latitude = 50, Longitude = 50 }; country.Coordinates = coordinates; } foreach (var timeZomeAsString in countryCreateModel.TimeZones) { var timeZone = new Countries.Domain.TimeZone { Name = timeZomeAsString }; if (this.context.TimeZones.Any(tz => tz.Name == timeZone.Name) == false) { this.context.TimeZones.Add(timeZone); var countryTimeZone = new CountryTimeZone { Country = country, TimeZone = timeZone }; this.context.CountryTimeZone.Add(countryTimeZone); } } foreach (var borderAsString in countryCreateModel.Borders) { var border = new Border { Name = borderAsString }; if (this.context.Borders.Any(tz => tz.Name == border.Name) == false) { this.context.Borders.Add(border); var countryBorder = new CountryBorder { Country = country, Border = border }; this.context.CountryBorder.Add(countryBorder); } } foreach (var currencyCreateModel in countryCreateModel.Currencies) { var currency = new Currency { Code = currencyCreateModel.Code, Name = currencyCreateModel.Name, Symbol = currencyCreateModel.Symbol }; if (this.context.Currencies.Any(c => c.Code == currency.Code) == false) { this.context.Currencies.Add(currency); var countryCurrency = new CountryCurrency { Country = country, Currency = currency }; this.context.CountryCurrency.Add(countryCurrency); } } foreach (var languageCreateModel in countryCreateModel.Languages) { var language = new Language { Iso639_1 = languageCreateModel.Iso639_1, Iso639_2 = languageCreateModel.Iso639_2, Name = languageCreateModel.Name, NativeName = languageCreateModel.NativeName, }; if (this.context.Languages.Any(l => l.Name == language.Name) == false) { this.context.Languages.Add(language); var countryLanguage = new CountryLanguage { Country = country, Language = language }; this.context.CountryLanguage.Add(countryLanguage); } } var translations = new Translations { De = countryCreateModel.Translations.De, Es = countryCreateModel.Translations.Es, Fr = countryCreateModel.Translations.Fr, Ja = countryCreateModel.Translations.Ja, It = countryCreateModel.Translations.It, Br = countryCreateModel.Translations.Br, Pt = countryCreateModel.Translations.Pt, Nl = countryCreateModel.Translations.Nl, Hr = countryCreateModel.Translations.Hr, Fa = countryCreateModel.Translations.Fa, }; country.Translations = translations; foreach (var blockCreateModel in countryCreateModel.Blocks) { var regionalBlock = new RegionalBlock { Acronym = blockCreateModel.Acronym, Name = blockCreateModel.Name }; if (this.context.RegionalBlocks.Any(rb => rb.Name == regionalBlock.Name) == false) { this.context.RegionalBlocks.Add(regionalBlock); var countryRegionalBlock = new CountryRegionalBlock { Country = country, RegionalBlock = regionalBlock }; this.context.CountryRegionalBlock.Add(countryRegionalBlock); } } this.context.Countries.Add(country); this.context.SaveChanges(); } return(this.Ok($"Successfully populated table with {this.context.Countries.Count()} countries.")); } return(this.Ok("Database is already populated.")); }