public async void GetAll_ReturnsAsyncOk()
        {
            var serviceMock = new Mock <ICrudService <Guid, TestEntity> >();

            serviceMock.Setup(_ => _.GetAllAsync()).ReturnsAsync(_entities);
            var controller = new CrudControllerBase <Guid, TestEntity>(serviceMock.Object);

            var actionResult = await controller.GetAll();

            var objectResult = actionResult.Result as OkObjectResult;
            var model        = objectResult.Value as IEnumerable <TestEntity>;

            Assert.Equal(model.Count(), _entities.Count);
            serviceMock.Verify(_ => _.GetAllAsync(), Times.Once);
        }
示例#2
0
        public async Task GetAll()
        {
            // Arrange
            var objList = new UserEntity[]
            {
                new UserEntity()
            };

            _crudService.Setup(x => x.GetAll())
            .Returns(Task.FromResult <IEnumerable <UserEntity> >(objList));

            // Act
            var controller = new CrudControllerBase <UserEntity>(_logger.Object, _crudService.Object);
            var result     = await controller.GetAll();

            // Assert
            Assert.IsType <OkObjectResult>(result.Result);
        }