public async Task GetCountAsync_ShouldResturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var countriesRepository = new EfDeletableEntityRepository <Country>(context);
            var countriesService    = new CountriesService(countriesRepository);
            var seeder = new DbContextTestsSeeder();
            var count  = await seeder.SeedCountriesAsync(context);

            var expectedCount = await countriesService.GetCountAsync();

            Assert.True(expectedCount == count, ErrorMessage);
        }
        public async Task GetAllWithPaging_ShouldReturnCorrectResult(int?take, int skip)
        {
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var countriesRepository = new EfDeletableEntityRepository <Country>(context);
            var countriesService    = new CountriesService(countriesRepository);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCountriesAsync(context);

            var countries = await countriesService.GetAllWithPagingAsync <CountryServiceDetailsModel>(take, skip);

            var countriesCount = countries.ToList().Count;

            Assert.True(take == countriesCount, ErrorMessage);
        }
        public async Task GetByIdAsync_ShouldreturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var countriesRepository = new EfDeletableEntityRepository <Country>(context);
            var countriesService    = new CountriesService(countriesRepository);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCountriesAsync(context);

            var expectedCountryId = await countriesRepository.All()
                                    .Where(c => c.Name == "Bulgaria")
                                    .Select(c => c.Id)
                                    .FirstOrDefaultAsync();

            var actualCountry = await countriesService.GetByIdAsync <CountryServiceDetailsModel>(expectedCountryId);

            Assert.True(expectedCountryId == actualCountry.Id, ErrorMessage);
        }
        public async Task EditAsync_ShouldReturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var countriesRepository = new EfDeletableEntityRepository <Country>(context);
            var countriesService    = new CountriesService(countriesRepository);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCountriesAsync(context);

            var countryFromDb = await countriesRepository.All().FirstOrDefaultAsync();

            var country = countryFromDb.To <CountryServiceDetailsModel>();

            country.Name = "BGN";
            var result = await countriesService.EditAsync(country);

            Assert.True(result == 1, ErrorMessage);
        }
        public async Task DeleteAllByIdAsync_ShouldReturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var countriesRepository = new EfDeletableEntityRepository <Country>(context);
            var countriesService    = new CountriesService(countriesRepository);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCountriesAsync(context);

            var expectedIds = await countriesRepository.All()
                              .Select(c => c.Id)
                              .ToListAsync();

            var actulaIds = await countriesService.DeleteAllByIdAsync(expectedIds);

            var areEquivalent = (expectedIds.Count == actulaIds.ToList().Count) && !expectedIds.Except(actulaIds.ToList()).Any();

            Assert.True(areEquivalent, ErrorMessage);
        }
        public async Task GetAllByCountryIdAsync_ShouldReturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var townRepository    = new EfDeletableEntityRepository <Town>(context);
            var countryRepository = new EfDeletableEntityRepository <Country>(context);
            var townsService      = new TownsService(townRepository);
            var seeder            = new DbContextTestsSeeder();
            await seeder.SeedCountriesAsync(context);

            await seeder.SeedTownsAsync(context);

            var countryId = await countryRepository.All()
                            .Select(c => c.Id)
                            .FirstOrDefaultAsync();

            var result = await townsService.GetAllByCountryIdAsync(countryId);

            Assert.True(result.ToList().Count == 1, ErrorMessage);
        }