Example #1
0
        public async void ProcessarPagamento_Test_Sucesso()
        {
            //Given
            var commandMock = new Mock <IPagamentoCommand>();

            var faker = AutoFaker.Create();

            var param = faker.Generate <CartaoParam>();

            var response = "Pagamento realizado com sucesso!";

            var baseControllerMock = new PagamentoController(commandMock.Object);
            var expectResponse     = baseControllerMock.Ok(response);

            commandMock.Setup(r => r.ProcessarPagamento(It.IsAny <CartaoParam>())).ReturnsAsync(new List <string>()).Verifiable();

            //When
            var result = await baseControllerMock.Post(param);

            //Then
            var comparison = new CompareLogic();

            commandMock.Verify(mock => mock.ProcessarPagamento(It.IsAny <CartaoParam>()), Times.Once());
            Assert.True(comparison.Compare(result, expectResponse).AreEqual);
        }
Example #2
0
        public async Task E_Possivel_Realizar_Cotroller_BadRequest()
        {
            var serviceMock = new Mock <IPagamentoService>();
            var Valor       = Faker.RandomNumber.Next(0, 10000);
            var cartao      = new cartao
            {
                titular        = Faker.Name.FullName(),
                numero         = Faker.Name.FullName(),
                cvv            = Faker.Name.FullName(),
                bandeira       = Faker.Name.FullName(),
                data_expiracao = Faker.Name.FullName()
            };

            _controller = new PagamentoController(serviceMock.Object);
            _controller.ModelState.AddModelError("Name", "É um campo obrigatório");
            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;
            var PagamentoDtoCreate = new PagamentoDtoCreate
            {
                Valor  = Valor,
                Cartao = cartao,
            };

            var result = await _controller.Post(PagamentoDtoCreate);

            ObjectResult resultValue = Assert.IsType <ObjectResult>(result);

            Assert.Equal(400, resultValue.StatusCode);
            Assert.Equal(resultValue.Value, "Ocorreu um Erro Desconhecido");
        }
Example #3
0
        public async void ObterPorId_DeveRetornarBadRequest()
        {
            // Arrange
            var pagamentoAppService = new Mock <IPagamentoAppService>();
            var notificador         = new Mock <INotificador>();
            var cache = new Mock <IDistributedCache>();
            var pagamentoDtoEsperado = new PagamentoDTO()
            {
                DataCadastro     = DateTimeOffset.Now,
                IdPagamento      = Guid.NewGuid(),
                ValorPagamento   = 1,
                ValorPagoCliente = 1,
                ValorTroco       = 0,
                TrocoItems       = new List <TrocoItemDTO>()
            };

            pagamentoAppService.Setup(appService => appService.BuscarPorId(pagamentoDtoEsperado.IdPagamento))
            .ReturnsAsync(pagamentoDtoEsperado);

            notificador.Setup(n => n.TemNotificacao()).Returns(true);
            notificador.Setup(n => n.ObterNotificacoes()).Returns(new List <Notificacao>()
            {
                new Notificacao("erro 1"), new Notificacao("erro 2")
            });

            var controller = new PagamentoController(pagamentoAppService.Object, notificador.Object, cache.Object);

            // Act
            var retorno = await controller.BuscarPorId(pagamentoDtoEsperado.IdPagamento);

            // Assert
            Assert.IsType <ActionResult <PagamentoDTO> >(retorno);
            Assert.IsType <BadRequestObjectResult>(retorno.Result);
        }
Example #4
0
        public async Task E_Possivel_Realizar_Cotroller_OutRange()
        {
            var serviceMock = new Mock <IPagamentoService>();
            var Valor       = Faker.RandomNumber.Next(-10, 0);
            var cartao      = new cartao
            {
                titular        = Faker.Name.FullName(),
                numero         = Faker.Name.FullName(),
                cvv            = Faker.Name.FullName(),
                bandeira       = Faker.Name.FullName(),
                data_expiracao = Faker.Name.FullName(),
            };

            _controller = new PagamentoController(serviceMock.Object);
            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;
            var PagamentoDtoCreate = new PagamentoDtoCreate
            {
                Valor  = Valor,
                Cartao = cartao,
            };

            var result = await _controller.Post(PagamentoDtoCreate);

            ObjectResult resultValue = Assert.IsType <ObjectResult>(result);

            Assert.Equal(412, resultValue.StatusCode);
            Assert.Equal(resultValue.Value, "Os valores informados não são válidos");
        }
Example #5
0
        public async void ObterPorId_DeveRetornarNotFound()
        {
            // Arrange
            var pagamentoAppService = new Mock <IPagamentoAppService>();
            var notificador         = new Mock <INotificador>();
            var cache = new Mock <IDistributedCache>();

            var controller = new PagamentoController(pagamentoAppService.Object, notificador.Object, cache.Object);

            // Act
            var retorno = await controller.BuscarPorId(Guid.NewGuid());

            // Assert
            Assert.IsType <ActionResult <PagamentoDTO> >(retorno);
            Assert.IsType <NotFoundResult>(retorno.Result);
        }
Example #6
0
        public async void Pagar_DeveRetornarOk()
        {
            // Arrange
            var pagamentoAppService = new Mock <IPagamentoAppService>();
            var notificador         = new Mock <INotificador>();
            var cache = new Mock <IDistributedCache>();

            notificador.Setup(n => n.TemNotificacao()).Returns(false);

            var controller = new PagamentoController(pagamentoAppService.Object, notificador.Object, cache.Object);

            // Act
            var retorno = await controller.Pagar(new PagamentoInputDTO()
            {
                ValorPagoCliente = 2, ValorPagamento = 2
            });

            // Assert
            Assert.IsType <ActionResult <PagamentoDTO> >(retorno);
            Assert.IsType <OkObjectResult>(retorno.Result);
        }
Example #7
0
        public async void ProcessarPagamento_Test_InternalServerError()
        {
            //Given
            var commandMock = new Mock <IPagamentoCommand>();

            var faker = AutoFaker.Create();

            var param = faker.Generate <CartaoParam>();

            var baseControllerMock = new PagamentoController(commandMock.Object);
            var expectResponse     = baseControllerMock.StatusCode(500);

            commandMock.Setup(r => r.ProcessarPagamento(It.IsAny <CartaoParam>())).ThrowsAsync(new Exception()).Verifiable();

            //When
            var result = await baseControllerMock.Post(param);

            //Then
            var comparison = new CompareLogic();

            commandMock.Verify(mock => mock.ProcessarPagamento(It.IsAny <CartaoParam>()), Times.Once());
            Assert.True(comparison.Compare(((ObjectResult)result).StatusCode, expectResponse.StatusCode).AreEqual);
        }
Example #8
0
        public async void Pagar_DeveRetornarModelStateInvalido()
        {
            // Arrange
            var pagamentoAppService = new Mock <IPagamentoAppService>();
            var notificador         = new Mock <INotificador>();
            var cache = new Mock <IDistributedCache>();

            notificador.Setup(n => n.TemNotificacao()).Returns(true);
            notificador.Setup(n => n.ObterNotificacoes()).Returns(new List <Notificacao>()
            {
                new Notificacao("Erro 1")
            });

            var controller = new PagamentoController(pagamentoAppService.Object, notificador.Object, cache.Object);

            controller.ModelState.AddModelError("1", "Erro 1");

            // Act
            var retorno = await controller.Pagar(new PagamentoInputDTO());

            // Assert
            Assert.IsType <ActionResult <PagamentoDTO> >(retorno);
            Assert.IsType <BadRequestObjectResult>(retorno.Result);
        }
Example #9
0
        public async Task E_Possivel_Realizar_Cotroller_Created()
        {
            var serviceMock = new Mock <IPagamentoService>();
            var Valor       = Faker.RandomNumber.Next(0, 10000);
            var cartao      = new cartao
            {
                titular        = Faker.Name.FullName(),
                numero         = Faker.Name.FullName(),
                cvv            = Faker.Name.FullName(),
                bandeira       = Faker.Name.FullName(),
                data_expiracao = Faker.Name.FullName(),
            };


            _controller = new PagamentoController(serviceMock.Object);
            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;
            var PagamentoDtoCreate = new PagamentoDtoCreate
            {
                Valor  = Valor,
                Cartao = cartao,
            };


            var result = await _controller.Post(PagamentoDtoCreate);

            Assert.True(result is OkObjectResult);

            var resultValue = ((OkObjectResult)result).Value as PagamentoDtoCreateResult;

            Assert.NotNull(resultValue);
            Assert.Equal(PagamentoDtoCreate.Valor, resultValue.Valor);
            Assert.Equal("Aprovado", resultValue.Estado);
        }
Example #10
0
        public TelaPagamento()
        {
            InitializeComponent();

            this.pagamentoControl = new PagamentoController();
        }
Example #11
0
 public string ProcessarPagamento([FromBody] PagamentoController pagamento)
 {
     return(_processarPagamento.ExecutarProcessamento(_mensageriaPagametos, new Pagamentos(pagamento.tipoPagamento, pagamento.valor)).Result);
 }