Пример #1
0
        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 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 <List <SampleContinent> > GetAll()
 {
     try
     {
         logger.LogInformation("ContinentController : GetAll => " + DateTime.Now);
         return(ContinentManager.GetAll().Select(s => new SampleContinent
         {
             ID = $"https://localhost:5001/api/Continent/{s.ID}",
             Name = s.Name,
             Population = s.Population,
             Countries = CountryManager.GetByContinentName(s).Select(k => $"https://localhost:5001/api/Continent/{s.ID}/Country/" + k.ID.ToString()).ToList()
         }).ToList());
     }
     catch
     {
         Response.StatusCode = 400;
         return(null);
     }
 }
Пример #4
0
        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();
        }
Пример #5
0
        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();
        }