Ejemplo n.º 1
0
        public void TestPoProcessCheck()
        {
            //Input
            var account = AccountFactory.Build();
            var date    = DateTime.Now;

            //behavior
            var accounts = new List <Account>();

            _mockAccountRepository.Setup(m => m.List())
            .Returns(accounts);

            var balances = new List <Balance>();

            _mockBalanceRepository.Setup(m => m.ToProcess(date, accounts))
            .Returns(balances);



            //test
            var val = _service.ToProcess(date);


            //assert
            Assert.IsInstanceOf <List <Balance> >(val);
            Assert.AreEqual(balances, val);
            _mockAccountRepository.Verify(x => x.List(), Times.Once());
            _mockBalanceRepository.Verify(x => x.ToProcess(date, accounts), Times.Once());
        }
Ejemplo n.º 2
0
        public void TestEnqueToPayFail(decimal entryVal, decimal charges, decimal saldo)
        {
            //Input
            var entry = EntryFactory.Build(x => { x.Type = "payment"; x.FinancialCharges = charges; x.Value = entryVal; });

            //behavior
            var account = AccountFactory.Build();

            _mockAccountRepository.Setup(m => m.FindOrCreateBy(It.IsAny <string>(),
                                                               It.IsAny <string>(),
                                                               It.IsAny <string>(),
                                                               It.IsAny <string>()))
            .Returns(account);

            var balance = BalanceFactory.Build(x => x.Total = saldo);

            _mockBalanceRepository.Setup(m => m.LastByOrDefault(It.IsAny <Account>(), It.IsAny <DateTime>()))
            .Returns(balance);

            _mockPaymentQueue.Setup(m => m.Enqueue(entry, null)).Verifiable();

            //test
            var val = _service.EnqueueToPay(entry);

            //assert
            Assert.IsInstanceOf <ErrorsDTO>(val.Result);
            Assert.AreSame("Account don't have especial limit", ((ErrorsDTO)val.Result).Details["valor_do_lancamento"][0]);
            _mockPaymentQueue.Verify(x => x.Enqueue(entry, null), Times.Never());
        }
Ejemplo n.º 3
0
        public void TestEnqueToPayOk(decimal entryVal, decimal charges, decimal saldo)
        {
            //Input
            var entry = EntryFactory.Build(x => { x.Type = "payment"; x.FinancialCharges = charges; x.Value = entryVal; });

            //behavior
            var account = AccountFactory.Build();

            _mockAccountRepository.Setup(m => m.FindOrCreateBy(It.IsAny <string>(),
                                                               It.IsAny <string>(),
                                                               It.IsAny <string>(),
                                                               It.IsAny <string>()))
            .Returns(account);

            var balance = BalanceFactory.Build(x => x.Total = saldo);

            _mockBalanceRepository.Setup(m => m.LastByOrDefault(It.IsAny <Account>(), It.IsAny <DateTime>()))
            .Returns(balance);

            _mockPaymentQueue.Setup(m => m.Enqueue(entry, null)).Verifiable();

            //It.IsAny<Entry>(

            //test
            var val = _service.EnqueueToPay(entry);


            //assert
            Assert.IsInstanceOf <OkDTO>(val.Result);
            Assert.AreEqual(entry.UUID, ((OkDTO)val.Result).UUID);
            _mockPaymentQueue.Verify(x => x.Enqueue(entry, null), Times.Once());
        }
        public void TestSave()
        {
            var entry = AccountFactory.Build();

            _repository.Save(entry);
            Assert.IsNotNull(entry.Id);
        }
        public void TestFindOrCreateNotExistAccount()
        {
            var created = AccountFactory.Build();
            var finded  = _repository.FindOrCreateBy(created.Number, created.Bank, created.Type, created.Identity);

            Assert.IsNotNull(finded.Id);
            Assert.AreEqual(_repository.Count(), 1);
        }
Ejemplo n.º 6
0
            public void Succeed_With_Valid_Request(
                AccountHolder holder,
                AccountFactory sut)
            {
                var result = sut.Build(holder);

                Assert.True(result.Balance.Amount == 0);
                Assert.True(result.Holder.FirstName == holder.FirstName);
            }
Ejemplo n.º 7
0
        public void TestPaySucessul(decimal entryVal, decimal charges, decimal saldo)
        {
            //Input
            var entry = EntryFactory.Build(x =>
            {
                x.Type             = "pagamento";
                x.Value            = entryVal;
                x.FinancialCharges = charges;
            });

            //behavior
            var account = AccountFactory.Build();

            _mockAccountRepository.Setup(m => m.FindOrCreateBy(It.IsAny <string>(),
                                                               It.IsAny <string>(),
                                                               It.IsAny <string>(),
                                                               It.IsAny <string>()))
            .Returns(account);

            var balance = BalanceFactory.Build(x => x.Total = saldo);

            _mockBalanceRepository.Setup(m => m.FindOrCreateBy(account, It.IsAny <DateTime>()))
            .Returns(balance);

            _mockBalanceRepository.Setup(m => m.LastByOrDefault(It.IsAny <Account>(), It.IsAny <DateTime>()))
            .Returns(balance);

            _mockEntryRepository.Setup(m => m.BeginTransaction()).Verifiable();
            _mockEntryRepository.Setup(m => m.Commit()).Verifiable();

            //test
            var val = _service.Pay(entry);

            //assert
            Assert.IsInstanceOf <OkDTO>(val.Result);
            Assert.AreEqual(entry.UUID, ((OkDTO)val.Result).UUID);
            _mockEntryRepository.Verify(x => x.Save(entry), Times.Once());
            _mockBalanceRepository.Verify(x => x.Update(balance), Times.Once());

            Assert.AreEqual(1, balance.Outputs.Count);
            Assert.AreEqual(1, balance.Charges.Count);
            Assert.AreEqual(0, balance.Inputs.Count);
        }
Ejemplo n.º 8
0
        public void TestCashFlowWhenHasAccount()
        {
            //Input
            var account = AccountFactory.Build();

            //behavior
            _mockAccountRepository.Setup(m => m.FindBy(account.Number, account.Bank, account.Type, account.Identity))
            .Returns(account);

            var balances = new List <Balance>();

            _mockBalanceRepository.Setup(m => m.ListTodayMore30Ahead(account.Id))
            .Returns(balances);


            //test
            var val = _service.CashFlow(account);


            //assert
            Assert.IsInstanceOf <List <Balance> >(val);
            Assert.AreEqual(balances, val);
            _mockBalanceRepository.Verify(x => x.ListTodayMore30Ahead(account.Id), Times.Once());
        }