public async Task Delete_Success() { var id = 4; var connection = await GetOpenSqliteConnectionAsync(); try { var options = new DbContextOptionsBuilder <PeopleContext>() .UseSqlite(connection) .Options; await SeedDataAsync(options); using (var context = new PeopleContext(options)) { var service = new PeopleService(context); await service.DeleteAsync(id); await service.SaveAsync(); } using (var context = new PeopleContext(options)) { var service = new PeopleService(context); var people = await service.ListAsync(); people.Should().NotBeNullOrEmpty(); people.Should().HaveCount(4); } } finally { connection.Close(); } }
public async Task Delete_NegativeId_Failure() { var connection = await GetOpenSqliteConnectionAsync(); try { var options = new DbContextOptionsBuilder <PeopleContext>() .UseSqlite(connection) .Options; await SeedDataAsync(options); using (var context = new PeopleContext(options)) { var service = new PeopleService(context); Func <Task> func = () => service.DeleteAsync(-1); func.Should().Throw <ArgumentException>(); } } finally { connection.Close(); } }
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()); }