public async void GetByIdAsync_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.GetByIdAsync(Guid.Empty));
        }
        public async void GetByIdAsync_ReturnOneElement()
        {
            var repositoryMock = new Mock <ICrudRepository>();

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

            var result = await service.GetByIdAsync(Guid.Empty);

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