public async void DeleteAsync_ThrowsEntityNotFoundException() { var repositoryMock = new Mock <ICrudRepository>(); repositoryMock.Setup(_ => _.GetByIdAsync <Guid, TestEntity>(It.IsAny <Guid>())).ThrowsAsync(new EntityNotFoundException()); var service = new CrudServiceBase <Guid, TestEntity>(repositoryMock.Object); await Assert.ThrowsAsync <EntityNotFoundException>(() => service.DeleteAsync(Guid.Empty)); }
public async void DeleteAsync_ReturnsDeletedElement() { var repositoryMock = new Mock <ICrudRepository>(); repositoryMock.Setup(_ => _.GetByIdAsync <Guid, TestEntity>(_entity.Id)).ReturnsAsync(_entity); var service = new CrudServiceBase <Guid, TestEntity>(repositoryMock.Object); var result = await service.DeleteAsync(_entity.Id); Assert.Equal(_entity.Id, result.Id); repositoryMock.Verify(_ => _.GetByIdAsync <Guid, TestEntity>(It.IsAny <Guid>()), Times.Once()); repositoryMock.Verify(_ => _.DeleteAsync <Guid, TestEntity>(It.IsAny <Guid>()), Times.Once); repositoryMock.Verify(_ => _.SaveChangesAsync(), Times.Once); }
public async Task <T2> DeleteAsync(T1 id) => await _service.DeleteAsync(id);