예제 #1
0
        public async Task DeleteByCountryIdWorksCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var addressesService = new Mock <IAddressesService>();

            var repository = new EfDeletableEntityRepository <City>(dbContext);

            var service = new CitiesService(repository, addressesService.Object);
            var city    = new City()
            {
                Id        = 1,
                CountryId = 1,
            };

            var city2 = new City()
            {
                Id        = 2,
                CountryId = 1,
            };

            var city3 = new City()
            {
                Id        = 3,
                CountryId = 2,
            };

            dbContext.Add(city);
            dbContext.Add(city2);
            dbContext.Add(city3);
            await dbContext.SaveChangesAsync();

            await service.DeleteByCountryIdAsync(1);

            var citiesInDb = dbContext.Cities.ToList();

            Assert.Single(citiesInDb);
        }