Пример #1
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 CountryRepositoryFunction_AddCountry_FunctionalityTest()
        {
            GeographyContextTest context       = new GeographyContextTest(true);
            CountryRepository    countryRepo   = new CountryRepository(context);
            ContinentRepository  continentRepo = new ContinentRepository(context);

            Continent continent = new Continent("Continent60");

            context.SaveChanges();

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

            countryRepo.AddCountry(4, "Country60", 20, 30.0f);
            context.SaveChanges();

            var countryFromRepo = countryRepo.GetCountry(4, 2);

            continentRepo.HasCountries(4).Should().BeTrue();

            countryFromRepo.Name.Should().Be("Country60");
            countryFromRepo.Population.Should().Be(20);
            countryFromRepo.Surface.Should().Be(30.0f);
            countryFromRepo.Continent.Name.Should().Be("Continent60");
        }
        //Create
        public void CreateContinent(ContinentViewModel continent)
        {
            using (var repository = new ContinentRepository())
            {
                var ContinentDbModel = new Continent
                {
                    Id   = continent.Id,
                    Name = continent.Name
                };

                repository.AddContinent(ContinentDbModel);
            }
        }