public async void UpdateAsync_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.UpdateAsync(Guid.Empty, _entity));
        }
        public async void UpdateAsync_ReturnsUpdatedElement()
        {
            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.UpdateAsync(_entity.Id, _entity);

            Assert.Equal(_entity.Id, result.Id);
            repositoryMock.Verify(_ => _.GetByIdAsync <Guid, TestEntity>(It.IsAny <Guid>()), Times.Once());
            repositoryMock.Verify(_ => _.SaveChangesAsync(), Times.Once);
        }
Esempio n. 3
0
 public async Task <T2> UpdateAsync(T1 id, T2 entity) => await _service.UpdateAsync(id, entity);