Exemplo n.º 1
0
        public async Task DeleteAsyncWorksCorrectly()
        {
            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,
            };

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

            await service.DeleteAsync(1);

            var dbCity = dbContext.Cities.FirstOrDefault(c => c.Id == 1);

            Assert.Null(dbCity);
        }
Exemplo n.º 2
0
        public async Task DeleteAsync_RemovesEntity()
        {
            //Assert

            //Act
            await testedService.DeleteAsync(singleEntity.Id);

            //Assert
            Mock.Verify(c => c.Remove(anyEntity), Times.Once());
            Mock.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }