Пример #1
0
 public ActionResult <ContinentInApi> PostContinent([FromBody] ContinentInApi continentAPI)
 {
     logger.LogInformation($"Post api/continent/ called");
     try
     {
         if (continentAPI == null)
         {
             return(BadRequest());
         }
         Domain.Models.Continent continent        = ContinentMapper.ContinentInMapper(countryManager, continentAPI);
         Domain.Models.Continent continentCreated = continentManager.AddContinent(continent);
         if (continentCreated != null)
         {
             ContinentOutApi continentOut = ContinentMapper.ContinentOutMapper(hostUrl, continentCreated);
             return(CreatedAtAction(nameof(GetContinent), new { id = continentOut.Id }, continentOut));
         }
         else
         {
             logger.LogError("Continent can not be null.");
             return(NotFound("Continent can not be null."));
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message);
         return(NotFound(ex.Message));
     }
 }
Пример #2
0
        private static void Main(string[] args)
        {
            ContinentManager continentManager = new ContinentManager(new UnitOfWork());
            CountryManager   countryManager   = new CountryManager(new UnitOfWork());

            Continent continent1       = new Continent("Antartica");
            Continent continent2       = new Continent("Europe");
            Continent continent1WithId = continentManager.AddContinent(continent1);
            Continent continent2WithId = continentManager.AddContinent(continent2);
            Country   country1         = new Country("Tuvalu", 11792, 30, continent1WithId);
            Country   country2         = new Country("Nauru", 10824, 20, continent1WithId);

            countryManager.AddCountry(country1);
            countryManager.AddCountry(country2);
        }
Пример #3
0
        public void AddContinent_ShouldAddContinentAndUpdateCountries_IfContinentIsValid()
        {
            // Arrange
            Continent      continent1     = new Continent("Africa");
            Continent      continent1InDb = continentManager.AddContinent(continent1);
            Country        country1       = new Country("Afghanistan", 38928346, 652.860, continent1InDb);
            Country        country2       = new Country("Albania", 2877797, 27.400, continent1InDb);
            Country        country1InDb   = countryManager.AddCountry(country1);
            Country        country2nDb    = countryManager.AddCountry(country2);
            List <Country> countries      = new List <Country>();

            countries.Add(country1InDb); countries.Add(country2nDb);
            Continent continent2 = new Continent("Asia", countries);

            // Act
            continentManager.AddContinent(continent2);
            Continent continent2InDb = continentManager.Find("Asia");

            // Assert
            continent2InDb.Should().BeEquivalentTo(continent2, options => options.Excluding(o => o.Id));
        }