コード例 #1
0
        public async Task GetAllAsync_Null()
        {
            //Arrange
            List <Role> roles = null;

            _roleRepositoryMock.Setup(m => m.GetAllAsync()).Returns(() => Task.FromResult(roles));
            RoleBusiness roleBusiness = new RoleBusiness(_roleRepositoryMock.Object);

            //Act
            var result = await roleBusiness.GetAllAsync();

            //Assert
            result.Should().BeNull();
        }
コード例 #2
0
        public async Task <ActionResult> GetAll()
        {
            try
            {
                List <Role> roles = await _roleBusiness.GetAllAsync();

                if (roles == null)
                {
                    return(NotFound());
                }

                List <RoleDto> rolesDto = _mapper.Map <List <RoleDto> >(roles);

                return(Ok(rolesDto));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ocorreu um erro ao buscar a role");
                return(StatusCode(500, "Ocorreu um erro ao buscar a role"));
            }
        }