public async void CopyAsync_ThrowsEntityNotFoundException()
        {
            var repositoryMock = new Mock <ICrudRepository>();

            repositoryMock.Setup(_ => _.GetByIdAsync <Guid, TestEntity>(It.IsAny <Guid>())).ReturnsAsync(default(TestEntity));
            var service = new CrudServiceBase <Guid, TestEntity>(repositoryMock.Object);

            await Assert.ThrowsAsync <EntityNotFoundException>(() => service.CopyAsync(Guid.Empty));
        }
        public async void CopyAsync_ReturnsCreatedElement()
        {
            var repositoryMock = new Mock <ICrudRepository>();

            repositoryMock.Setup(_ => _.GetByIdAsync <Guid, TestEntity>(It.IsAny <Guid>())).ReturnsAsync(_entity);
            repositoryMock.Setup(_ => _.CreateAsync <Guid, TestEntity>(It.IsAny <TestEntity>())).ReturnsAsync(_entity);
            var service = new CrudServiceBase <Guid, TestEntity>(repositoryMock.Object);

            var result = await service.CopyAsync(_entity.Id);

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