Exemple #1
0
        public void MapperFunction_ToDContinent_FunctionalityTest()
        {
            string    continentName = "Continent";
            Continent continent     = new Continent(continentName);

            string  countryName       = "Country";
            int     countryPopulation = 14000;
            float   countrySurface    = 7500.50f;
            Country country           = new Country(countryPopulation, countryName, countrySurface, continent);

            string  countryName2       = "Country 2";
            int     countryPopulation2 = 18000;
            float   countrySurface2    = 7500.50f;
            Country country2           = new Country(countryPopulation2, countryName2, countrySurface2, continent);

            continent.AddCountry(country);
            continent.AddCountry(country2);

            DContinent mappedDContinent = Mapper.ToDContinent(continent);

            mappedDContinent.Name.Should().Be(continentName);
            mappedDContinent.Population.Should().Be(countryPopulation + countryPopulation2);

            mappedDContinent.Countries.Count.Should().Be(2);
            mappedDContinent.Countries[0].Name.Should().Be(countryName);
            mappedDContinent.Countries[0].Surface.Should().Be(countrySurface);
            mappedDContinent.Countries[0].Population.Should().Be(countryPopulation);
            mappedDContinent.Countries[1].Name.Should().Be(countryName2);
            mappedDContinent.Countries[1].Surface.Should().Be(countrySurface2);
            mappedDContinent.Countries[1].Population.Should().Be(countryPopulation2);
        }
        public void ContinentAddCountryAlreadyInTest()
        {
            Continent continent = new Continent("Azië");
            Country   country   = new Country("vietnam", 95540000, 331.212f, continent);

            continent.AddCountry(country);
            Action act = () => continent.AddCountry(country);

            act.Should().Throw <ArgumentException>().WithMessage("country already added.");
        }
        public void ContinentFunction_AddCountry_FuncionalityTest()
        {
            string    continentName = "Continent";
            Continent continent     = new Continent(continentName);

            string  countryName       = "Country";
            int     countryPopulation = 14000;
            float   countrySurface    = 7500.50f;
            Country country           = new Country(countryPopulation, countryName, countrySurface, continent);

            continent.AddCountry(country);

            continent.Population.Should().Be(countryPopulation);

            continent.Countries.Count.Should().Be(1);

            continent.Countries[0].Name.Should().Be(countryName);
            continent.Countries[0].Name.Should().Be(countryName);
            continent.Countries[0].Name.Should().Be(countryName);


            continent.Population.Should().Be(countryPopulation);

            continent.AddCountry(country);


            continent.Countries.Count.Should().Be(1);

            continent.Countries[0].Name.Should().Be(countryName);
            continent.Countries[0].Name.Should().Be(countryName);
            continent.Countries[0].Name.Should().Be(countryName);



            string  countryName2       = "Country2";
            int     countryPopulation2 = 77000;
            float   countrySurface2    = 10000.50f;
            Country country2           = new Country(countryPopulation2, countryName2, countrySurface2, continent);


            continent.AddCountry(country2);

            continent.Population.Should().Be(countryPopulation + countryPopulation2);

            continent.Countries.Count.Should().Be(2);

            continent.Countries[0].Name.Should().Be(countryName);
            continent.Countries[0].Name.Should().Be(countryName);
            continent.Countries[0].Name.Should().Be(countryName);
            continent.Countries[1].Name.Should().Be(countryName2);
            continent.Countries[1].Name.Should().Be(countryName2);
            continent.Countries[1].Name.Should().Be(countryName2);
        }
Exemple #4
0
        public void HasCountry_condition_expectedValue()
        {
            Continent continent = new Continent(5, "Asia");
            Country   country1  = new Country(8, "India", 88, 510000);
            Country   country2  = new Country(5, "China", 1000, 11111111);
            Country   country3  = new Country(10, "Japan0", 106564, 5100445400.454564);

            continent.AddCountry(country1);
            continent.AddCountry(country2);
            continent.AddCountry(country3);

            continent.Countries.Count.Should().Be(3);
        }
Exemple #5
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 void ContinentFunction_RemoveCountry_ExceptionsTest()
        {
            string    continentName = "Continent";
            Continent continent     = new Continent(continentName);


            Action act = () => continent.RemoveCountry(null);

            act.Should().Throw <DomainException>().WithMessage("Er zijn geen landen in dit continent");

            string  countryName       = "Country";
            int     countryPopulation = 14000;
            float   countrySurface    = 7500.50f;
            Country country           = new Country(countryPopulation, countryName, countrySurface, continent);

            continent.AddCountry(country);

            act = () => continent.RemoveCountry(null);

            act.Should().Throw <DomainException>().WithMessage("Een land mag niet null zijn");

            string    continentName2 = "Continent 2";
            Continent continent2     = new Continent(continentName2);

            string  countryName2       = "Country 2";
            int     countryPopulation2 = 14000;
            float   countrySurface2    = 7500.50f;
            Country country2           = new Country(countryPopulation2, countryName2, countrySurface2, continent2);

            act = () => continent.RemoveCountry(country2);

            act.Should().Throw <DomainException>().WithMessage("Het gegeven land is niet in dit continent.");
        }
Exemple #7
0
        public void ContinentRepositoryFunction_AddContinent_FunctionalityTest()
        {
            GeographyContextTest context = new GeographyContextTest(false);
            ContinentRepository  repo    = new ContinentRepository(context);

            Continent continent  = new Continent("Continent");
            Continent continent2 = new Continent("Continent2");

            Continent continent3 = new Continent("Continent4");

            continent3.AddCountry(new Country(12, "Country1", 20.0f, continent3));

            repo.AddContinent(continent);
            context.SaveChanges();

            repo.AddContinent(continent2);
            context.SaveChanges();

            repo.AddContinent(continent3);
            context.SaveChanges();


            repo.GetContinent(1).Name.Should().Be(continent.Name);
            repo.GetContinent(2).Name.Should().Be(continent2.Name);

            var continentWithCountries = repo.GetContinent(3);

            continentWithCountries.Name.Should().Be(continent3.Name);

            continentWithCountries.Countries.Count.Should().Be(1);
            continentWithCountries.Countries[0].Name.Should().Be("Country1");
            continentWithCountries.Countries[0].Population.Should().Be(12);
            continentWithCountries.Countries[0].Surface.Should().Be(20.0f);
        }
        public void ContinentAddCountryCheckPopulationTest()
        {
            Continent continent = new Continent("Azië");
            Country   country   = new Country("vietnam", 95540000, 331.212f, continent);

            continent.AddCountry(country);
            continent.Population.Should().Be(95540000);
        }
        public void ContinentFunction_AddCountry_ExceptionsTest()
        {
            string    continentName = "Continent";
            Continent continent     = new Continent(continentName);

            Action act = () => continent.AddCountry(null);

            act.Should().Throw <DomainException>().WithMessage("Een land mag niet null zijn");
        }
        public void ContinentDeleteCountryTest()
        {
            Continent continent = new Continent("Azië");
            Country   country   = new Country("vietnam", 95540000, 331.212f, continent);

            continent.AddCountry(country);
            Action act = () => continent.DeleteCountry(country);

            act.Should().NotThrow();
        }
        public void ContinentDeleteCountryNullThrowsExceptionTest()
        {
            Continent continent = new Continent("Azië");
            Country   country   = new Country("vietnam", 95540000, 331.212f, continent);

            continent.AddCountry(country);
            Action act = () => continent.DeleteCountry(null);

            act.Should().Throw <ArgumentException>().WithMessage("country can't be null");
        }
Exemple #12
0
        public void AddCountry_ShouldAddCorrect_IfCountryDoesNotExist()
        {
            Continent continent = new Continent(5, "Asia");
            Country   country   = new Country(8, "India", 88, 510000);

            continent.AddCountry(country);

            continent.Countries.Count.Should().Be(1);
            continent.Countries.First().Should().BeEquivalentTo(country);
        }
Exemple #13
0
        public void AddCountry_ShouldChangeContinent_IfCountryHasOtherContinent()
        {
            Continent continent    = new Continent(5, "Asia");
            Continent newContinent = new Continent(2, "Europe");
            Country   country      = new Country(8, "India", 88, 510000, continent);

            newContinent.AddCountry(country);

            country.Continent.Should().BeEquivalentTo(newContinent);
        }
        public void ContinentDeleteCountryAlreadyRemovedThrowsExceptionTest()
        {
            Continent continent = new Continent("Azië");
            Country   country   = new Country("vietnam", 95540000, 331.212f, continent);

            continent.AddCountry(country);
            continent.DeleteCountry(country);
            Action act = () => continent.DeleteCountry(country);

            act.Should().Throw <ArgumentException>().WithMessage("country is not in Azië");
        }
Exemple #15
0
        public void AddCountry(int continentId, string countryName, int countryPopulation, float countrySurface)
        {
            DContinent dContinent = context.Continents.Include(c => c.Countries).Single(c => c.Id == continentId);

            Continent continent = Mapper.ToContinent(dContinent);

            continent.AddCountry(new Country(countryPopulation, countryName, countrySurface, continent));

            DCountry dCountry = Mapper.ToDCountry(continent.Countries.Last());

            dContinent.Countries.Add(dCountry);
            dContinent.Population = continent.Population;
        }
        public static Continent ContinentInMapper(CountryManager countryManager, ContinentInApi continentIn)
        {
            Continent continent = new Continent();

            continent.Name = continentIn.Name;
            if (continentIn.Countries != null)
            {
                foreach (var countryId in continentIn.Countries)
                {
                    Country country = countryManager.Find(countryId);
                    continent.AddCountry(country);
                }
            }
            return(continent);
        }
Exemple #17
0
        /// <summary>
        /// Maps a Continent object to a Continent object.
        /// </summary>
        /// <param name="continent">Continent to map.</param>
        /// <returns>The mapped Continent object.</returns>
        public static Continent ToContinent(DContinent dContinent)
        {
            Continent continent = new Continent(dContinent.Name)
            {
                Id = dContinent.Id
            };

            foreach (DCountry country in dContinent.Countries)
            {
                continent.AddCountry(ToCountry(country, continent));
            }


            return(continent);
        }
        public void ContinentFunction_RemoveCountry_FuncionalityTest()
        {
            string    continentName = "Continent";
            Continent continent     = new Continent(continentName);

            string  countryName       = "Country";
            int     countryPopulation = 14000;
            float   countrySurface    = 7500.50f;
            Country country           = new Country(countryPopulation, countryName, countrySurface, continent);

            continent.AddCountry(country);

            continent.RemoveCountry(country);

            continent.Population.Should().Be(0);

            continent.Countries.Count.Should().Be(0);
        }
Exemple #19
0
        public Continent Find(int continentId)
        {
            if (continentId < 0)
            {
                throw new ContinentManagerException("FindContinent - invalid id");
            }
            Continent continent = uow.Continents.Find(continentId);

            if (GetCountries(continentId).Count != 0)
            {
                foreach (var country in GetCountries(continentId))
                {
                    if (!continent.HasCountry(country))
                    {
                        continent.AddCountry(country);
                    }
                }
            }
            return(continent);
        }
Exemple #20
0
        public static Continent FromDContinentToContinent(DContinent dContinent)
        {
            Continent continent = new Continent(dContinent.Name)
            {
                Id = (uint)dContinent.Id,
            };

            if (dContinent.Countries.Count > 0)
            {
                foreach (DCountry dCountry in dContinent.Countries)
                {
                    Country toAdd = new Country(dCountry.Name, dCountry.Population, dCountry.Surface, continent)
                    {
                        Id = (uint)dCountry.Id
                    };
                    continent.AddCountry(toAdd);
                }
            }
            return(continent);
        }