Beispiel #1
0
        public void UpdateContinent_ShouldUpdateContinent_IfContinentExists()
        {
            // Arrange
            Continent continent1                = new Continent("Europe");
            Continent continent2                = new Continent("Europe 2.0");
            Continent continent1InDb            = continentManager.AddContinent(continent1);
            Continent continent2InDb            = continentManager.AddContinent(continent2);
            Country   country1                  = new Country("Algeria", 38928346, 652.860, continent1InDb);
            Country   country2                  = new Country("Andorra", 2877797, 27.400, continent2InDb);
            Country   country1InDb              = countryManager.AddCountry(country1);
            Country   country2InDb              = countryManager.AddCountry(country2);
            Continent continent1InDbWithCountry = continentManager.Find(continent1InDb.Id);

            Continent continentUpdated = continent1InDbWithCountry;

            continentUpdated.Name = "East-Europe";
            continentUpdated.AddCountry(country2InDb);

            // Act
            continentManager.UpdateContinent(continent1InDb.Id, continentUpdated);
            Continent updatedContinentInDb = continentManager.Find(continentUpdated.Id);

            // Assert
            updatedContinentInDb.Name.Should().Be("East-Europe");
            updatedContinentInDb.Countries.Count.Should().Be(2);
        }
 public IActionResult PutContinent(int id, [FromBody] ContinentInApi continentIn)
 {
     logger.LogInformation($"Put api/continent/ called");
     if (continentIn == null)
     {
         return(BadRequest());
     }
     try
     {
         if (continentManager.Find(id) == null)
         {
             Domain.Models.Continent continent        = ContinentMapper.ContinentInMapper(countryManager, continentIn);
             Domain.Models.Continent continentCreated = continentManager.AddContinent(continent);
             ContinentOutApi         continentOut     = ContinentMapper.ContinentOutMapper(hostUrl, continentCreated);
             return(CreatedAtAction(nameof(GetContinent), new { id = continentOut.Id }, continentOut));
         }
         Domain.Models.Continent continentUpdate = ContinentMapper.ContinentInMapper(countryManager, continentIn);
         continentUpdate.Id = id;
         continentManager.UpdateContinent(id, continentUpdate);
         return(new NoContentResult());
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message);
         return(BadRequest(ex.Message));
     }
 }
Beispiel #3
0
        public ActionResult <SampleContinent> Put(int id, [FromBody] SampleContinent sampleContinent)
        {
            try
            {
                var continent = ContinentManager.GetContinentById(id);

                if (ContinentManager.ContinentExists(new Continent(continent.Name)))
                {
                    continent.SetName(continent.Name);
                    ContinentManager.UpdateContinent(continent);
                    return(CreatedAtAction(nameof(GetContinent), new { id = continent.ID }, continent));
                }
                else
                {
                    return(BadRequest("Continent error"));
                }
            }
            catch (Exception ex)
            {
                return(NotFound("Continent not found!"));
            }
        }
Beispiel #4
0
        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();
        }