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

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

            var address = new Address()
            {
                Id = 1,
                CityId = 1,
            };

            var addressTwo = new Address()
            {
                Id = 2,
                CityId = 1,
            };

            dbContext.Add(address);
            dbContext.Add(addressTwo);
            await dbContext.SaveChangesAsync();

            var service = new AddressesService(repository);
            await service.DeleteByCityIdAsync(1);
            var addressesInDbCount = repository.All().ToList().Count();

            Assert.Equal(0, addressesInDbCount);
        }