Exemple #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);
        }
Exemple #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");
        }
Exemple #3
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");
        }
Exemple #4
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);
        }
Exemple #5
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);
        }