Example #1
0
        public async Task GetByIdAsync_Null()
        {
            //Arrange
            Role role = null;

            _roleRepositoryMock.Setup(m => m.GetByIdAsync(It.IsAny <int>())).Returns(() => Task.FromResult(role));
            RoleBusiness roleBusiness = new RoleBusiness(_roleRepositoryMock.Object);

            //Act
            var result = await roleBusiness.GetByIdAsync(Role.Id);

            //Assert
            result.Should().BeNull();
        }
        public async Task <ActionResult> GetById(int id)
        {
            try
            {
                Role role = await _roleBusiness.GetByIdAsync(id);

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

                RoleDto roleDto = _mapper.Map <RoleDto>(role);

                return(Ok(roleDto));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ocorreu um erro ao buscar a role");
                return(StatusCode(500, $"Ocorreu um erro ao buscar a role. Id: {id}"));
            }
        }
Example #3
0
        public async Task GetByIdAsync_Role()
        {
            //Arrange
            _roleRepositoryMock.Setup(m => m.GetByIdAsync(It.IsAny <int>())).Returns(() => Task.FromResult(Role));
            RoleBusiness roleBusiness = new RoleBusiness(_roleRepositoryMock.Object);

            //Act
            var result = await roleBusiness.GetByIdAsync(Role.Id);

            //Assert
            result.Should().NotBeNull();
            result.Id.Should().BeGreaterThan(0);
            result.Id.Should().Be(Role.Id);
            result.Name.Should().NotBeNullOrEmpty();
            result.Name.Should().Be(Role.Name);
            result.Description.Should().NotBeNullOrEmpty();
            result.Description.Should().Be(Role.Description);
            result.Active.Should().Be(Role.Active);
            result.CreatedAt.Should().HaveYear(DateTime.Now.Year);
            result.CreatedAt.Should().HaveMonth(DateTime.Now.Month);
            result.CreatedAt.Should().HaveDay(DateTime.Now.Day);
            result.CreatedAt.Should().HaveHour(DateTime.Now.Hour);
            result.CreatedAt.Should().HaveMinute(DateTime.Now.Minute);
        }