public async Task Handle_deve_retornar_verdadeiro_se_cancelar_com_sucesso_as_permissoes()
        {
            //arrange
            var permissao1 = Guid.NewGuid();
            var permissao  = _list.FirstOrDefault();

            permissao.Ativo = false;

            var perfil = TestBuilder.PerfilFalso();

            _perfilRepositoryMock.Setup(p => p.ObterComPermissoesAsync(It.IsAny <Guid>())).ReturnsAsync(perfil);
            _service.Setup(s => s.RevogarPermissaoAsync(It.IsAny <Perfil>(), It.IsAny <Guid>()))
            .ReturnsAsync(perfil);

            _uow.Setup(u => u.Commit()).ReturnsAsync(CommandResponse.Ok);
            var command     = new AtribuirPermissaoCommand(perfil.Id, _list);
            var cancelToken = new System.Threading.CancellationToken();

            //act
            var result = await _handler.Handle(command, cancelToken);

            //assert
            result.Success.Should().BeTrue();
            _mediator.Verify(m => m.Publish(It.IsAny <PermissaoAssinadaEvent>(), default), Times.Once());
        }
示例#2
0
        public async Task Deve_Cancelar_Permissoes_e_Retornar_Ok()
        {
            //arrange
            _mediator.Setup(s => s.Send(It.IsAny <IRequest <CommandResponse> >(), new System.Threading.CancellationToken()))
            .ReturnsAsync(CommandResponse.Ok).Verifiable();
            var permissao = new AtribuirPermissaoCommand(

                perfilId: Guid.NewGuid(),
                atribuicoes: new List <AtribuicaoDTO>()
            {
                new AtribuicaoDTO()
                {
                    PermissaoId = Guid.NewGuid(),
                    Ativo       = false
                }
            }
                );

            //act
            var result = await _controller.AtribuirPermissoesAsync(permissao);

            //assert
            result.Should().BeAssignableTo <OkResult>();
            var vr = result as OkResult;

            vr.StatusCode.Should().Be(StatusCodes.Status200OK);
        }
        public async Task Deve_AssinarPermissao_e_Retornar_True()
        {
            //arrange
            var perfil = TestBuilder.PerfilFalso();

            _service.Setup(s => s.AtribuirPermissaoAsync(It.IsAny <Perfil>(), It.IsAny <Guid>()))
            .ReturnsAsync(perfil);
            var command = new AtribuirPermissaoCommand(perfil.Id, _list);
            //act
            var result = await _handler.Handle(command, new System.Threading.CancellationToken());

            //assert
            result.Success.Should().BeTrue();
            _service.Verify(s => s.AtribuirPermissaoAsync(perfil, It.IsAny <Guid>()), Times.Once);
            _uow.Verify(u => u.Commit(), Times.Once);
        }
        public async Task Handle_deve_retornar_falso_se_perfil_nao_existir()
        {
            //arrange
            var perfilId = Guid.NewGuid();

            _perfilRepositoryMock.Setup(r => r.ObterComPermissoesAsync(It.IsAny <Guid>()))
            .ReturnsAsync((Perfil)null);

            var command     = new AtribuirPermissaoCommand(perfilId, _list);
            var cancelToken = new System.Threading.CancellationToken();

            //act
            var result = await _handler.Handle(command, cancelToken);

            //assert
            result.Success.Should().BeFalse();
        }
示例#5
0
        public async Task <IActionResult> AtribuirPermissoesAsync([FromBody] AtribuirPermissaoCommand command)
        {
            var result = await _mediator.Send(command);

            return(this.VerificarErros(_notifications, result));
        }