コード例 #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();
        }
コード例 #2
0
        public ActionResult Add()
        {
            if ((string)Session["user"] != "admin")
            {
                return(RedirectToAction("../Home/Login"));
            }
            CountryVM countryVM = new CountryVM();

            countryVM.Countries = _countryManager.GetAll();
            return(View(countryVM));
        }
コード例 #3
0
        private void LoadCountry()
        {
            List <Country> country = CountryManager.GetAll();

            CountryGridView.DataSource = country;
            CountryGridView.DataBind();
        }
コード例 #4
0
 private void FillDropDownListWithCountryInforamtion()
 {
     countryDropDownList.DataSource     = countryManager.GetAll();
     countryDropDownList.DataValueField = "Id";
     countryDropDownList.DataTextField  = "Name";
     countryDropDownList.DataBind();
 }
コード例 #5
0
        public void GetAll_AllCountriesCanListed()
        {
            ICountryService countryService = new CountryManager(_mockCountryDal.Object);
            List <Country>  countries      = countryService.GetAll().Data;

            Assert.AreEqual(3, countries.Count);
        }
コード例 #6
0
 public ActionResult Post([FromBody] SampleRiver river)
 {
     try
     {
         List <Country> tempList = new List <Country>();
         foreach (var country in CountryManager.GetAll())
         {
             if (river.Countries.Contains(country.ID.ToString()))
             {
                 tempList.Add(country);
             }
         }
         if (tempList.Count == river.Countries.Count)
         {
             logger.LogInformation("RiverController : Get => " + DateTime.Now);
             River x = new River(river.Name, river.Lenght, tempList);
             RiverManager.Add(x);
             return(CreatedAtAction(nameof(Get), new { id = x.ID }, x));
         }
         else
         {
             return(NotFound("Country input not found"));
         }
     }catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #7
0
        private void LoadAllCountry()
        {
            List <Country> countries = countryManager.GetAll();

            countryDropDownList.DataSource     = countries;
            countryDropDownList.DataValueField = "Id";
            countryDropDownList.DataTextField  = "Name";
            countryDropDownList.DataBind();
        }
 private void LoadAllCountry()
 {
     try
     {
         countryList = countryManager.GetAll();
         showCountryInforamotionGridView.DataSource = countryList;
         showCountryInforamotionGridView.DataBind();
     }
     catch (Exception exceptionObj)
     {
         message = exceptionObj.Message;
         if (exceptionObj.InnerException != null)
         {
             message += "<br/>System Error:" + exceptionObj.InnerException.Message;
         }
         messageLabel.ForeColor = System.Drawing.Color.Red;
         messageLabel.Text      = message;
     }
 }
コード例 #9
0
        private void LoadCountry()
        {
            CountryManager countryManager = new CountryManager();

            CountryDropDownList.DataSource = null;
            List <Country> country = CountryManager.GetAll();

            CountryDropDownList.DataSource     = country;
            CountryDropDownList.DataTextField  = "CountryName";
            CountryDropDownList.DataValueField = "id";
            CountryDropDownList.DataBind();
        }
コード例 #10
0
 private void FillDropDownListWithCountryInforamtion()
 {
     try
     {
         countryDropDownList.DataSource     = countryManager.GetAll();
         countryDropDownList.DataValueField = "Id";
         countryDropDownList.DataTextField  = "Name";
         countryDropDownList.DataBind();
     }
     catch (Exception exceptionObj)
     {
         message = exceptionObj.Message;
         if (exceptionObj.InnerException != null)
         {
             message += "<br/>System Error:" + exceptionObj.InnerException.Message;
         }
         messageLabel.ForeColor = System.Drawing.Color.Red;
         messageLabel.Text      = message;
     }
 }
コード例 #11
0
        public ActionResult <SampleRiver> Get(int id)
        {
            try
            {
                var temp = RiverManager.Get(id);
                if (temp == null)
                {
                    return(NotFound("River is not found"));
                }
                logger.LogInformation("RiverController : Get => " + DateTime.Now);

                var MainList = new List <Country>();

                List <Country> tempCountries = CountryManager.GetAll().FindAll(s => s.Rivers.Count != 0).ToList();

                foreach (var country in tempCountries)
                {
                    foreach (var river in country.Rivers)
                    {
                        if (river.ID == id)
                        {
                            MainList.Add(country);
                        }
                    }
                }


                return(new SampleRiver {
                    ID = temp.ID,
                    Name = temp.Name,
                    Lenght = temp.Lenght,
                    Countries = MainList.Select(s => $"https://localhost:5001/api/Continent/{s.Continent.ID}/Country/" + s.ID).ToList()
                });
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #12
0
        public ActionResult <SampleRiver> Put(int id, [FromBody] SampleRiver river)
        {
            try
            {
                var temp = RiverManager.Get(id);
                if (temp == null)
                {
                    return(NotFound("River is not found"));
                }
                else
                {
                    List <Country> tempList = new List <Country>();
                    foreach (var country in CountryManager.GetAll())
                    {
                        if (river.Countries.Contains(country.ID.ToString()))
                        {
                            tempList.Add(country);
                        }
                    }
                    if (tempList.Count == river.Countries.Count)
                    {
                        logger.LogInformation("RiverController : Put => " + DateTime.Now);

                        RiverManager.Update(temp, river.Name, river.Lenght, tempList);
                        return(Ok());
                    }
                    else
                    {
                        return(NotFound("Country input not found"));
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #13
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();
        }
コード例 #14
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();
        }
コード例 #15
0
 private void LoadAllCountry()
 {
     countryList = countryManager.GetAll();
     showCountryInforamotionGridView.DataSource = countryList;
     showCountryInforamotionGridView.DataBind();
 }
コード例 #16
0
 public HttpResponseMessage Get()
 {
     return(Request.CreateResponse(CountryManager.GetAll()));
 }