public void Country_Manager_Test() { CountryManager tempCountry = new CountryManager(new UnitOfWork(new DataContext("test"))); ContinentManager tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test"))); tempCountry.RemoveAll(); tempContinent.RemoveAll(); tempContinent.Add(new Continent("test-Continent")); tempContinent.Add(new Continent("test-Continent1")); List <Continent> continents = tempContinent.GetAll(); Assert.AreEqual(2, continents.Count); Assert.AreEqual("test-Continent", continents[0].Name); tempCountry.Add(new Country("test", 500, 200, continents[0])); tempCountry.Add(new Country("test-Country1", 50, 20, continents[0])); List <Country> countries = tempCountry.GetAll(); Country country1 = tempCountry.Get(countries[0].ID); Country country2 = tempCountry.Get(countries[1].ID); Assert.AreEqual(2, countries.Count); Assert.AreEqual("test", country1.Name); Assert.AreEqual("test-Country1", country2.Name); Assert.AreEqual(500, country1.Population); Assert.AreEqual(50, country2.Population); Assert.AreEqual(200, country1.Surface); Assert.AreEqual(20, country2.Surface); tempCountry.Update(country1, "test-Country", 2000, 10, continents[1]); countries = tempCountry.GetAll(); country1 = tempCountry.Get(countries[0].ID); country2 = tempCountry.Get(countries[1].ID); Assert.AreEqual(2, countries.Count); Assert.AreEqual("test-Country", country1.Name); Assert.AreEqual("test-Country1", country2.Name); Assert.AreEqual(2000, country1.Population); Assert.AreEqual(50, country2.Population); Assert.AreEqual(10, country1.Surface); Assert.AreEqual(20, country2.Surface); tempCountry.Remove(country1.ID); countries = tempCountry.GetAll(); Assert.AreEqual(1, countries.Count); tempCountry.RemoveAll(); tempContinent.RemoveAll(); }
public void CountryManagerTest() { CityManager cityManager = new CityManager(new UnitOfWork(new DataContext())); CountryManager countryManager = new CountryManager(new UnitOfWork(new DataContext())); ContinentManager continentManager = new ContinentManager(new UnitOfWork(new DataContext())); //Verwijder alles in tabels cityManager.RemoveAll(); countryManager.RemoveAllCountries(); continentManager.RemoveAll(); //Aanmaak Continent continentManager.Add(new Continent("TestContinent")); List <Continent> continents = continentManager.GetAllContinents(); Continent continent = continents[0]; Assert.AreEqual(1, continents.Count); //Toevoegen van Country countryManager.Add(new Country("TestCountry", continent, 100, 10)); List <Country> countries = countryManager.GetAllCountries(); Country country = countries[0]; Assert.AreEqual(1, countries.Count); Assert.AreEqual("TestCountry", country.Name); //Verwijder alles in tabels cityManager.RemoveAll(); countryManager.RemoveAllCountries(); continentManager.RemoveAll(); }
public void Continent_Manager_Test() { ContinentManager temp = new ContinentManager(new UnitOfWork(new DataContext("test"))); temp.RemoveAll(); Continent con = new Continent("test-continent"); Assert.AreEqual(0, con.ID); temp.Add(con); temp.Add(new Continent("test-continent1")); List <Continent> continents = temp.GetAll(); Continent continent1 = temp.Get(continents[0].ID); Continent continent2 = temp.Get(continents[1].ID); Assert.AreEqual(2, continents.Count); Assert.AreEqual("test-continent", continent1.Name); Assert.AreEqual("test-continent1", continent2.Name); temp.Remove(continent1.ID); continents = temp.GetAll(); continent1 = temp.Get(continents[0].ID); Assert.AreEqual(1, continents.Count); Assert.AreEqual("test-continent1", continent1.Name); continent1.SetName("test"); temp.Update(continent1); continents = temp.GetAll(); continent1 = temp.Get(continents[0].ID); Assert.AreEqual("test", continent1.Name); temp.RemoveAll(); }
public ActionResult <SampleContinent> AddContinent([FromBody] SampleContinent sampleContinent) { try { Continent continent = new Continent(sampleContinent.Name); if (ContinentManager.ContinentExists(continent)) { ContinentManager.Add(continent); return(CreatedAtAction(nameof(GetContinent), new { id = continent.ID }, continent)); } else { return(BadRequest("Continent already exists!")); } } catch (Exception ex) { return(BadRequest("ERROR : " + ex)); } }
public ActionResult <SampleContinent> AddContinent([FromBody] Sample_Models.SampleContinent con) { try { Continent temp = new Continent(con.Name); if (ContinentManager.IfExist(temp)) { ContinentManager.Add(temp); logger.LogInformation("ContinentController : Add => " + DateTime.Now); return(CreatedAtAction(nameof(Get), new { id = temp.ID }, temp)); } else { return(BadRequest("Continent already exist")); } } catch (Exception e) { return(BadRequest("Something went wrong : " + e)); } }
public void ContinentManagerTest() { CityManager cityManager = new CityManager(new UnitOfWork(new DataContext())); CountryManager countryManager = new CountryManager(new UnitOfWork(new DataContext())); ContinentManager continentManager = new ContinentManager(new UnitOfWork(new DataContext())); //Verwijder alles in tabels cityManager.RemoveAll(); countryManager.RemoveAllCountries(); continentManager.RemoveAll(); //Aanmaak Continent continentManager.Add(new Continent("TestContinent")); List <Continent> continents = continentManager.GetAllContinents(); Continent continent = continents[0]; Assert.AreEqual(1, continents.Count); Assert.AreEqual("TestContinent", continent.Name); continent.SetName("TestContAangepast"); continent.SetPopulation(100); continentManager.UpdateContinent(continent); Assert.AreEqual("TestContAangepast", continent.Name); Assert.AreEqual(100, continent.Population); continentManager.RemoveContinent(continent.ID); continents = continentManager.GetAllContinents(); Assert.AreEqual(0, continents.Count); //Verwijder alles in tabels cityManager.RemoveAll(); countryManager.RemoveAllCountries(); continentManager.RemoveAll(); }
public void City_Manager_Test() { CityManager tempCity = new CityManager(new UnitOfWork(new DataContext("test"))); CountryManager tempCountry = new CountryManager(new UnitOfWork(new DataContext("test"))); ContinentManager tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test"))); tempCity.RemoveAll(); tempCountry.RemoveAll(); tempContinent.RemoveAll(); tempContinent.Add(new Continent("test-Continent")); tempContinent.Add(new Continent("test-Continent1")); List <Continent> continents = tempContinent.GetAll(); Assert.AreEqual(2, continents.Count); tempCountry.Add(new Country("test", 500, 200, continents[0])); tempCountry.Add(new Country("test-Country1", 50, 20, continents[0])); List <Country> countries = tempCountry.GetAll(); Country country1 = tempCountry.Get(countries[0].ID); Country country2 = tempCountry.Get(countries[1].ID); Assert.AreEqual(2, countries.Count); Assert.AreEqual("test", country1.Name); Assert.AreEqual("test-Country1", country2.Name); Assert.AreEqual(500, country1.Population); Assert.AreEqual(50, country2.Population); Assert.AreEqual(200, country1.Surface); Assert.AreEqual(20, country2.Surface); tempCity.Add(new City("test-city", 50, country1, true)); tempCity.Add(new City("test-city1", 150, country1, false)); tempCity.Add(new City("test-city2", 200, country1, false)); tempCity.Add(new City("test-city3", 10, country1, false)); var cities = tempCity.GetAll(); City city = tempCity.Get(cities[0].ID); City city1 = tempCity.Get(cities[1].ID); City city2 = tempCity.Get(cities[2].ID); City city3 = tempCity.Get(cities[3].ID); Assert.AreEqual(city.Name, "test-city"); Assert.AreEqual(city1.Name, "test-city1"); Assert.AreEqual(city2.Name, "test-city2"); Assert.AreEqual(city3.Name, "test-city3"); Assert.AreEqual(city.IsCapital, true); Assert.AreEqual(city1.IsCapital, false); Assert.AreEqual(city2.IsCapital, false); Assert.AreEqual(city3.IsCapital, false); Assert.AreEqual(city.Population, 50); Assert.AreEqual(city1.Population, 150); Assert.AreEqual(city2.Population, 200); Assert.AreEqual(city3.Population, 10); tempCity.Update(city3, "test", 50, false, country2); cities = tempCity.GetAll(); city = tempCity.Get(cities[0].ID); city1 = tempCity.Get(cities[1].ID); city2 = tempCity.Get(cities[2].ID); city3 = tempCity.Get(cities[3].ID); Assert.AreEqual(4, cities.Count); Assert.AreEqual(city.Name, "test-city"); Assert.AreEqual(city1.Name, "test-city1"); Assert.AreEqual(city2.Name, "test-city2"); Assert.AreEqual(city3.Name, "test"); Assert.AreEqual(city.IsCapital, true); Assert.AreEqual(city1.IsCapital, false); Assert.AreEqual(city2.IsCapital, false); Assert.AreEqual(city3.IsCapital, false); Assert.AreEqual(city.Population, 50); Assert.AreEqual(city1.Population, 150); Assert.AreEqual(city2.Population, 200); Assert.AreEqual(city3.Population, 50); tempCity.Remove(city.ID); cities = tempCity.GetAll(); Assert.AreEqual(3, cities.Count); tempCountry.Update(country1, country1.Name, 350, 250, country1.Continent); tempCity = new CityManager(new UnitOfWork(new DataContext("test"))); tempCountry = new CountryManager(new UnitOfWork(new DataContext("test"))); tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test"))); tempCity.RemoveAll(); tempCountry.RemoveAll(); tempContinent.RemoveAll(); }
public void River_Manager_Test() { CountryManager tempCountry = new CountryManager(new UnitOfWork(new DataContext("test"))); ContinentManager tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test"))); RiverManager tempRiver = new RiverManager(new UnitOfWork(new DataContext("test"))); tempRiver.RemoveAll(); tempCountry.RemoveAll(); tempContinent.RemoveAll(); tempContinent.Add(new Continent("test-Continent")); tempContinent.Add(new Continent("test-Continent1")); List <Continent> continents = tempContinent.GetAll(); Assert.AreEqual(2, continents.Count); Assert.AreEqual("test-Continent", continents[0].Name); tempCountry.Add(new Country("test", 500, 200, continents[0])); tempCountry.Add(new Country("test-Country1", 50, 20, continents[0])); List <Country> countries = tempCountry.GetAll(); Country country1 = tempCountry.Get(countries[0].ID); Country country2 = tempCountry.Get(countries[1].ID); Assert.AreEqual(2, countries.Count); Assert.AreEqual("test", country1.Name); Assert.AreEqual("test-Country1", country2.Name); Assert.AreEqual(500, country1.Population); Assert.AreEqual(50, country2.Population); Assert.AreEqual(200, country1.Surface); Assert.AreEqual(20, country2.Surface); tempRiver.Add(new River("test-river", 250, countries)); var rivers = tempRiver.GetAll(); var river = tempRiver.Get(rivers[0].ID); Assert.AreEqual(1, rivers.Count); Assert.AreEqual("test-river", river.Name); Assert.AreEqual(250, river.Lenght); country1 = tempCountry.Get(countries[0].ID); Assert.AreEqual(1, country1.Rivers.Count); Assert.AreEqual(2, river.Countries.Count); Assert.AreEqual("test", river.Countries[0].Name); Assert.AreEqual("test-Country1", river.Countries[1].Name); Assert.AreEqual(500, river.Countries[0].Population); Assert.AreEqual(50, river.Countries[1].Population); Assert.AreEqual(200, river.Countries[0].Surface); Assert.AreEqual(20, river.Countries[1].Surface); tempRiver.Update(river, "test", 50, countries); rivers = tempRiver.GetAll(); river = tempRiver.Get(rivers[0].ID); Assert.AreEqual("test", river.Name); Assert.AreEqual(50, river.Lenght); tempRiver.Remove(river.ID); rivers = tempRiver.GetAll(); Assert.AreEqual(0, rivers.Count); tempCountry = new CountryManager(new UnitOfWork(new DataContext("test"))); tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test"))); tempRiver = new RiverManager(new UnitOfWork(new DataContext("test"))); tempRiver.RemoveAll(); tempCountry.RemoveAll(); tempContinent.RemoveAll(); }