Example #1
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 #2
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);
        }