Esempio n. 1
0
 public PermissaoControllerTest()
 {
     _mediator      = new Mock <IMediator>();
     _notifications = new DomainNotificationHandler();
     _controller    = new PermissoesController(_mediator.Object, _notifications);
     _list          = new List <PermissaoViewModel>()
     {
         ViewModelBuilder.PermissaoViewFake(),
             ViewModelBuilder.PermissaoViewFake(),
             ViewModelBuilder.PermissaoViewFake(),
             ViewModelBuilder.PermissaoViewFake(),
     };
 }
Esempio n. 2
0
        public async Task Deve_Retornar_Ok_Ao_Editar_Permissao()
        {
            //arrange
            var permissao = ViewModelBuilder.PermissaoViewFake();
            var command   = new AtualizarPermissaoCommand(permissao.Id, permissao.Tipo, permissao.Valor);

            _mediator.Setup(s => s.Send(It.IsAny <IRequest <CommandResponse> >(), new System.Threading.CancellationToken()))
            .ReturnsAsync(CommandResponse.Ok);
            //act
            var result = await _controller.AtualizarPermissaoAsync(command);

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

            vr.StatusCode.Should().Be(StatusCodes.Status200OK);
        }
Esempio n. 3
0
        public async Task Deve_Retornar_BadRequest_Ao_Criar_Permissao()
        {
            //arrange
            var permissao = ViewModelBuilder.PermissaoViewFake();
            var command   = new CriarPermissaoCommand(permissao.Tipo, permissao.Valor);

            _mediator.Setup(s => s.Send(It.IsAny <IRequest <CommandResponse> >(), new System.Threading.CancellationToken()))
            .ReturnsAsync(CommandResponse.Fail.AddError("Erro Fake")).Verifiable();
            //act
            var result = await _controller.CriarPermissaoAsync(command);

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

            vr.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
        }
Esempio n. 4
0
        public async Task Deve_Cadastrar_Novo_Usuario_E_Retornar_Ok()
        {
            //arrange
            var usuario = ViewModelBuilder.UsuarioCommand();

            _mediator.Setup(s => s.Send(It.IsAny <IRequest <CommandResponse> >(), new System.Threading.CancellationToken()))
            .ReturnsAsync(CommandResponse.Ok).Verifiable();
            //act
            var result = await _controller.CriarUsuarioAsync(usuario);

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

            vr.StatusCode.Should().Be(StatusCodes.Status200OK);
            _mediator.Verify();
        }
Esempio n. 5
0
        public async Task Deve_Retornar_Um_Usuario_Ao_Passar_O_Id_Por_Parametro()
        {
            //arrange
            var usuarioFake = ViewModelBuilder.UsuarioFake();

            _mediator.Setup(s => s.Send(It.IsAny <IRequest <UsuarioViewModel> >(), new System.Threading.CancellationToken()))
            .ReturnsAsync(usuarioFake);
            //act
            var result = await _controller.GetUsuarioAsync(Guid.NewGuid());

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

            vr.Value.Should().Be(usuarioFake);
            vr.StatusCode.Should().Be(StatusCodes.Status200OK);
        }
Esempio n. 6
0
        public async Task Deve_Retornar_Uma_Permissao_Por_Id()
        {
            // arrange
            var permissaoViewModel = ViewModelBuilder.PermissaoViewFake();

            _mediator.Setup(s => s.Send(It.IsAny <IRequest <PermissaoViewModel> >(), new System.Threading.CancellationToken()))
            .ReturnsAsync(permissaoViewModel);

            //act
            var result = await _controller.GetPermissaoAsync(Guid.NewGuid());

            var vr = result as OkObjectResult;

            //assert

            result.Should().BeAssignableTo <OkObjectResult>();
            vr.Value.Should().Be(permissaoViewModel);
        }
Esempio n. 7
0
        public async Task Deve_Retornar_Lista_De_Usuarios_Cadastrados()
        {
            //arrange
            var list = new List <UsuarioViewModel>()
            {
                ViewModelBuilder.UsuarioFake(),
                ViewModelBuilder.UsuarioFake(),
                ViewModelBuilder.UsuarioFake(),
            };

            _mediator.Setup(s => s.Send(It.IsAny <IRequest <IEnumerable <UsuarioViewModel> > >(), new System.Threading.CancellationToken()))
            .ReturnsAsync(list).Verifiable();
            //act
            var result = await _controller.GetUsuariosAsync();

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

            vr.Value.Should().Be(list);
            vr.StatusCode.Should().Be(StatusCodes.Status200OK);
            _mediator.Verify();
        }