Beispiel #1
0
        public void Service_Conta_EfetuarTransferencia_DevePassar()
        {
            //Arrange
            _conta = ContaObjectMother.GetContaValida();
            Conta contaDestino = ContaObjectMother.GetContaComMovimentacao();

            contaDestino.Id = 2;

            int idContaOrigem  = 1;
            int idContaDestino = 2;

            _repositoryFake.Setup(x => x.GetById(idContaOrigem)).Returns(_conta);
            _repositoryFake.Setup(x => x.GetById(idContaDestino)).Returns(contaDestino);

            _repositoryFake.Setup(x => x.Update(_conta)).Returns(true);
            _repositoryFake.Setup(x => x.Update(contaDestino)).Returns(true);
            //Action
            _service.EfetuarTrasferencia(_conta.Id, contaDestino.Id, 1000);
            //Verify
            _repositoryFake.Verify(x => x.GetById(_conta.Id));
            _repositoryFake.Verify(x => x.Update(_conta));
            _repositoryFake.Verify(x => x.Update(contaDestino));
            _conta.SaldoTotal.Should().Be(ContaObjectMother.GetContaValida().SaldoTotal - 1000);
            contaDestino.SaldoTotal.Should().Be(ContaObjectMother.GetContaComMovimentacao().SaldoTotal + 1000);
        }
Beispiel #2
0
        public void Service_Conta_EfetuarTransferenciaSemLimite_NãoDevePermitir()
        {
            //Arrange
            _conta = ContaObjectMother.GetContaValida();
            Conta contaDestino = ContaObjectMother.GetContaComMovimentacao();

            contaDestino.Id = 2;
            int idContaOrigem  = 1;
            int idContaDestino = 2;

            _repositoryFake.Setup(x => x.GetById(idContaOrigem)).Returns(_conta);
            _repositoryFake.Setup(x => x.GetById(idContaDestino)).Returns(contaDestino);

            _repositoryFake.Setup(x => x.Update(_conta)).Returns(false);
            _repositoryFake.Setup(x => x.Update(contaDestino)).Returns(false);
            //Action
            Action action = () => _service.EfetuarTrasferencia(_conta.Id, contaDestino.Id, 5000);

            //Verify
            action.Should().Throw <ContaSaldoInsuficienteException>();
            _repositoryFake.Verify(x => x.GetById(_conta.Id));
            _repositoryFake.Verify(x => x.GetById(contaDestino.Id));
            _conta.SaldoTotal.Should().Be(ContaObjectMother.GetContaValida().SaldoTotal);
            contaDestino.SaldoTotal.Should().Be(ContaObjectMother.GetContaComMovimentacao().SaldoTotal);
            _repositoryFake.VerifyNoOtherCalls();
        }
Beispiel #3
0
 public void Service_Conta_EfetuarDeposito_DevePassar()
 {
     //Arrange
     _conta = ContaObjectMother.GetContaValida();
     _repositoryFake.Setup(x => x.Update(It.IsAny <Conta>()));
     _repositoryFake.Setup(x => x.GetById(It.IsAny <int>())).Returns(_conta);
     //Action
     _service.EfetuarDeposito(_conta.Id, 1000);
     //Verify
     _repositoryFake.Verify(x => x.Update(_conta));
     _conta.SaldoTotal.Should().Be(ContaObjectMother.GetContaValida().SaldoTotal + 1000);
 }
Beispiel #4
0
 public void Service_Conta_AlterarEstado_DevePassar()
 {
     //Arrange
     _conta = ContaObjectMother.GetContaValida();
     _repositoryFake.Setup(x => x.GetById(_conta.Id)).Returns(_conta);
     _repositoryFake.Setup(x => x.Update(_conta)).Returns(true);
     //Action
     _service.AlterarEstado(_conta.Id);
     //Verify
     _repositoryFake.Verify(x => x.Update(_conta));
     _conta.Ativada.Should().Be(!ContaObjectMother.GetContaValida().Ativada);
 }
Beispiel #5
0
        public void Service_Conta_PegarContaPorId_DeveJogarExcessao_NotFoundException()
        {
            //Arrange
            var conta = ContaObjectMother.GetContaValida();

            _repositoryFake.Setup(pr => pr.GetById(conta.Id)).Throws <NotFoundException>();
            //Action
            Action act = () => _service.GetById(conta.Id);

            //Assert
            act.Should().Throw <NotFoundException>();
            _repositoryFake.Verify(pr => pr.GetById(conta.Id), Times.Once);
        }
Beispiel #6
0
        public void Service_Conta_EfetuarTransferenciaErroAoGravarSaque_NãoDevePermitir()
        {
            //Arrange
            _conta = ContaObjectMother.GetContaValida();
            Conta contaDestino = ContaObjectMother.GetContaValida();

            _repositoryFake.Setup(x => x.GetById(It.IsAny <int>())).Returns(_conta);
            contaDestino.Id = 2;
            _repositoryFake.Setup(x => x.Update(It.IsAny <Conta>())).Returns(false);
            //Action
            _service.EfetuarTrasferencia(_conta.Id, contaDestino.Id, 1000);
            //Verify
            _repositoryFake.Verify(x => x.Update(_conta));
        }
Beispiel #7
0
        public void Setup()
        {
            var connection = DbConnectionFactory.CreatePersistent(Guid.NewGuid().ToString());

            _context    = new FakeDbContext(connection);
            _repository = new ContaRepository(_context);

            _conta = ContaObjectMother.GetContaValida();
            //Seed
            _contaSeed = ContaObjectMother.GetContaValida();
            _context.Contas.Add(_contaSeed);
            _context.Clientes.Add(_contaSeed.Cliente);
            _context.Clientes.Add(_conta.Cliente);
            _context.SaveChanges();
        }
Beispiel #8
0
        public void Controller_Contas_GetById_DevePassar()
        {
            // Arrange
            var conta = ContaObjectMother.GetContaValida();

            _contaServiceMock.Setup(c => c.GetById(conta.Id)).Returns(conta);
            // Action
            IHttpActionResult callback = _contasController.GetById(conta.Id);
            // Assert
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <ContaViewModel> >().Subject;

            httpResponse.Content.Should().NotBeNull();
            httpResponse.Content.Id.Should().Be(conta.Id);
            _contaServiceMock.Verify(s => s.GetById(conta.Id), Times.Once);
        }
Beispiel #9
0
        public void Service_Conta_EfetuarSaqueSemLimite_NãoDevePermitir()
        {
            //Arrange
            _conta = ContaObjectMother.GetContaValida();
            _repositoryFake.Setup(x => x.Update(It.IsAny <Conta>()));
            _repositoryFake.Setup(x => x.GetById(It.IsAny <int>())).Returns(_conta);
            //Action
            Action action = () => _service.EfetuarSaque(_conta.Id, 5000);

            //Verify
            action.Should().Throw <ContaSaldoInsuficienteException>();
            _conta.SaldoTotal.Should().Be(ContaObjectMother.GetContaValida().SaldoTotal);
            _repositoryFake.Verify(pr => pr.GetById(_conta.Id), Times.Once);
            _repositoryFake.Verify(pr => pr.Update(It.IsAny <Conta>()), Times.Never);
            _repositoryFake.VerifyNoOtherCalls();
        }
Beispiel #10
0
        public void Controller_Contas_GerarExtrato_DevePassar()
        {
            // Arrange
            var conta   = ContaObjectMother.GetContaValida();
            var extrato = conta.GerarExtrato();

            _contaServiceMock.Setup(s => s.GetExtrato(conta.Id)).Returns(extrato);
            // Action
            var callback = _contasController.GetExtrato(conta.Id);

            //Assert
            _contaServiceMock.Verify(s => s.GetExtrato(conta.Id), Times.Once);
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <Extrato> >().Subject;

            httpResponse.Content.Should().NotBeNull();
        }
Beispiel #11
0
        public void Service_Conta_AdicionarConta_DevePassar()
        {
            //Arrange
            var conta    = ContaObjectMother.GetContaValida();
            var contaCmd = ContaObjectMother.GetContaValidaParaRegistrar();

            _repositoryFake.Setup(x => x.Add(It.IsAny <Conta>()))
            .Returns(conta);
            _repositoryClienteFake.Setup(cl => cl.GetById(contaCmd.ClienteId)).Returns(conta.Cliente);
            //Action
            var novoContaId = _service.Add(contaCmd);

            //Verify
            _repositoryFake.Verify(x => x.Add(It.IsAny <Conta>()), Times.Once);
            novoContaId.Should().Be(conta.Id);
        }
Beispiel #12
0
        public void Service_Conta_AdicionarConta_Com_IdCliente_Inesistente_DeveJogarExcessao_NotFoundException()
        {
            //Arrange
            var conta    = ContaObjectMother.GetContaValida();
            var contaCmd = ContaObjectMother.GetContaValidaParaRegistrar();

            contaCmd.ClienteId = 20;
            // _repositoryFake.Setup(pr => pr.Add(conta));
            _repositoryClienteFake.Setup(cl => cl.GetById(contaCmd.ClienteId)).Returns((Cliente)null);
            //Action
            Action act = () => _service.Add(contaCmd);

            //Assert
            act.Should().Throw <NotFoundException>();
            //_repositoryFake.Verify(x => x.Add(conta), Times.Never);
            _repositoryClienteFake.Verify(pr => pr.GetById(contaCmd.ClienteId), Times.Once);
        }
Beispiel #13
0
        public void Service_Conta_AtualizarContaMudarNumero_Nao_Deve_Permitir()
        {
            //Arrange
            var conta    = ContaObjectMother.GetContaValida();
            var contaCmd = ContaObjectMother.GetContaValidaParaAtualizar();

            contaCmd.Id          = 1;
            contaCmd.NumeroConta = 1500;
            _repositoryFake.Setup(x => x.GetById(It.IsAny <int>())).Returns(conta);
            _repositoryClienteFake.Setup(cl => cl.GetById(contaCmd.ClienteId)).Returns(conta.Cliente);
            //Action
            Action act = () => _service.Update(contaCmd);

            //Verify
            act.Should().Throw <ContaNumeroAlteradoException>();
            _repositoryFake.Verify(x => x.GetById(It.IsAny <int>()));
            _repositoryFake.VerifyNoOtherCalls();
        }
Beispiel #14
0
        public void Service_Conta_AtualizarConta_DevePassar()
        {
            //Arrange
            var conta      = ContaObjectMother.GetContaValida();
            var contaCmd   = ContaObjectMother.GetContaValidaParaAtualizar();
            var atualizado = true;

            _repositoryFake.Setup(x => x.GetById(contaCmd.Id)).Returns(conta);
            _repositoryFake.Setup(pr => pr.Update(conta)).Returns(atualizado);
            _repositoryClienteFake.Setup(cl => cl.GetById(contaCmd.ClienteId)).Returns(conta.Cliente);
            //Action
            var contaAtualizado = _service.Update(contaCmd);

            //Verify
            _repositoryFake.Verify(pr => pr.GetById(contaCmd.Id), Times.Once);
            _repositoryFake.Verify(pr => pr.Update(conta), Times.Once);
            contaAtualizado.Should().BeTrue();
        }
Beispiel #15
0
        public void Controller_Contas_EfetuarTransferencia_DevePassar()
        {
            // Arrange
            var contaOrigem  = ContaObjectMother.GetContaValida();
            var contaDestino = ContaObjectMother.GetContaValidaParaAtualizar();

            contaDestino.Id = 2;
            var isUpdated = true;
            var valor     = 100;

            _contaServiceMock.Setup(c => c.EfetuarTrasferencia(contaOrigem.Id, contaDestino.Id, valor)).Returns(isUpdated);
            // Action
            IHttpActionResult callback = _contasController.EfetuarTransferencia(contaOrigem.Id, contaDestino.Id, valor);
            // Assert
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <bool> >().Subject;

            httpResponse.Content.Should().BeTrue();
            _contaServiceMock.Verify(s => s.EfetuarTrasferencia(contaOrigem.Id, contaDestino.Id, valor), Times.Once);
        }
Beispiel #16
0
        public void Controller_Contas_Get_DevePassar()
        {
            // Arrange
            var conta    = ContaObjectMother.GetContaValida();
            var response = new List <Conta>()
            {
                conta
            }.AsQueryable();

            _contaServiceMock.Setup(s => s.GetAll(0)).Returns(response);
            // Action
            var callback = _contasController.Get();

            //Assert
            _contaServiceMock.Verify(s => s.GetAll(0), Times.Once);
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <List <ContaViewModel> > >().Subject;

            httpResponse.Content.Should().NotBeNullOrEmpty();
            httpResponse.Content.First().Id.Should().Be(conta.Id);
        }
Beispiel #17
0
        public void Service_Conta_AtualizarConta_Com_IdCliente_Inesistente_DeveJogarExcessao_NotFoundException()
        {
            //Arrange
            var conta    = ContaObjectMother.GetContaValida();
            var contaCmd = ContaObjectMother.GetContaValidaParaAtualizar();

            contaCmd.ClienteId = 20;
            var atualizado = false;

            _repositoryFake.Setup(x => x.GetById(contaCmd.Id)).Returns(conta);
            _repositoryFake.Setup(pr => pr.Update(conta)).Returns(atualizado);
            _repositoryClienteFake.Setup(cl => cl.GetById(contaCmd.ClienteId)).Returns((Cliente)null);
            //Action
            Action act = () => _service.Update(contaCmd);

            //Assert
            act.Should().Throw <NotFoundException>();
            _repositoryFake.Verify(pr => pr.GetById(contaCmd.Id), Times.Once);
            _repositoryClienteFake.Verify(pr => pr.GetById(contaCmd.ClienteId), Times.Once);
            _repositoryFake.Verify(pr => pr.Update(It.IsAny <Conta>()), Times.Never);
        }
Beispiel #18
0
        public void Controller_Contas_Get_Com_Quantidade_E_Outros_Filtros_DevePassar()
        {
            // Arrange
            var conta    = ContaObjectMother.GetContaValida();
            var uri      = "http://localhost:9001/api/contas?numero=123";
            var response = new List <Conta>()
            {
                conta, conta, conta
            }.AsQueryable();

            _contaServiceMock.Setup(s => s.GetAll(0)).Returns(response);
            _contasController.Request = GetUri(uri);
            // Action
            var callback = _contasController.Get();

            //Assert
            _contaServiceMock.Verify(s => s.GetAll(0), Times.Once);
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <List <ContaViewModel> > >().Subject;

            httpResponse.Content.Should().NotBeNullOrEmpty();
            httpResponse.Content.First().Id.Should().Be(conta.Id);
        }