internal void AddCountriesFromApi(int number) { int counter = 0; try { _countries = _countryDAO.GetAll().ToList(); HttpResponseMessage httpResponse = client.GetAsync(url + "?results=" + number).Result; for (int i = 0; i < number; i++) { if (httpResponse.IsSuccessStatusCode) { Country c = new Country(); var content = httpResponse.Content.ReadAsStringAsync().Result; APIUser aPIUser = JsonConvert.DeserializeObject <APIUser>(content); if (!_countries.Any(country => country.CountryName == aPIUser.results[i].location.city)) { c.CountryName = aPIUser.results[i].location.city; _countryDAO.Add(c); counter++; } ProgressValue += Convert.ToInt32(1.0 / Total * 100); } _countries = _countryDAO.GetAll().ToList(); Message = $"Created Countries {counter}/ {number}\n"; } } catch (Exception e) { Message += $"{e.ToString()}\n"; } }
public void CreateNewCountryTest() { CountryDAOMSSQL c = new CountryDAOMSSQL(); Country country = new Country("Las-Vegas"); Assert.AreEqual(c.GetAll().Count, 1); TestCenter.AdminFacade.CreateNewCountry(TestCenter.AdminToken, country); Assert.AreEqual(c.GetAll().Count, 2); }
public void CountryFuncsTest() { FlightDAOMSSQL flight = new FlightDAOMSSQL(); flight.RemoveAll(); CountryDAOMSSQL c = new CountryDAOMSSQL(); c.RemoveAll(); AirlineDAOMSSQL airline = new AirlineDAOMSSQL(); airline.RemoveAll(); Country c1, c2; c1 = new Country("UAE"); c2 = new Country("England"); CountryDAOMSSQL country = new CountryDAOMSSQL(); country.RemoveAll(); country.Add(c1); country.Add(c2); country.Remove(c2); IList <Country> countries = country.GetAll(); Country updatedCountry = country.Get(c1.Id); updatedCountry.CountryName = "Spain"; country.Update((updatedCountry)); Assert.AreEqual(updatedCountry, countries[0]); }
public bool DataBaseStatus() { AirLineDAOMSSQL alDAO = new AirLineDAOMSSQL(); CountryDAOMSSQL cDAO = new CountryDAOMSSQL(); CustomerDAOMSSQL custDAO = new CustomerDAOMSSQL(); if (alDAO.GetAll().Count() == 0 && cDAO.GetAll().Count() == 0 && custDAO.GetAll().Count() == 0) { return(true); } return(false); }
public void PurchaseTicketCustomerIDZeroException() { Country israel = new Country("Israel"); countryDAO.Add(israel); israel = countryDAO.GetAll()[0]; AirlineCompany elal = new AirlineCompany("ELAL", "ELALUSERNAME", "ELALPASSWORD", israel.ID); airlineDAO.Add(elal); elal = airlineDAO.GetAll()[0]; Flight theFlight = new Flight(elal.ID, israel.ID, israel.ID, new DateTime((DateTime.Now.Year + 2), 12, 5, 14, 00, 00), new DateTime((DateTime.Now.Year + 2), 12, 7, 14, 00, 00), 50, FlightStatus.NotDeparted); flightDAO.Add(theFlight); theFlight = flightDAO.GetAll()[0]; LoginToken <Customer> loggedInCustomer = new LoginToken <Customer>(); loggedInCustomer.user = new Customer(); facade.PurchaseTicket(loggedInCustomer, theFlight); }
/// <summary> /// method that selects the appropriate method for adding a a database member depending on the this class Generic parameter ("T") /// </summary> private void Initialize() { _countries = _countryDAO.GetAll(); _airlineCompanies = _airlineCompanyDAO.GetAll(); _flights = _flightDAO.GetAll(); _customers = _customerDAO.GetAll(); _utility_user_types.Add(typeof(Administrator)); _utility_user_types.Add(typeof(Customer)); _utility_user_types.Add(typeof(AirlineCompany)); _genericTypeMethodCorrelation.Add(typeof(Customer), AddCustomers); _genericTypeMethodCorrelation.Add(typeof(Administrator), AddAdministrators); _genericTypeMethodCorrelation.Add(typeof(Flight), AddFlights); _genericTypeMethodCorrelation.Add(typeof(Country), this.AddCountries); _genericTypeMethodCorrelation.Add(typeof(AirlineCompany), this.AddAirlineCompanies); _genericTypeMethodCorrelation.Add(typeof(Ticket), this.AddTickets); //add more "Add["type_name"]" functions to the dictionary when they created }
public void CreateNewCountry() { facade.CreateNewCountry(new Country("Israel")); Assert.AreEqual(1, countryDAO.GetAll().Count); Assert.AreEqual("Israel", countryDAO.GetAll()[0].CountryName); }