Exemplo n.º 1
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());
        }
        public void TestFindExistentEntity()
        {
            var created = BalanceFactory.Create();
            var finded  = _repository.Find(created.Id.GetValueOrDefault());

            Assert.AreEqual(created.Id, finded.Id);
        }
Exemplo 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 balance = BalanceFactory.Build(x =>
            {
                x.Inputs.Clear();
                x.Inputs.Add(new ShortEntryDTO(DateTime.Today, 100m));
            });

            _repository.Save(balance);
            Assert.IsNotNull(balance.Id);
            Assert.AreEqual(balance.Inputs.Count, 1);
        }
        public void TestUpdatedEntity()
        {
            var created = BalanceFactory.Create();

            //update value
            created.Total += 2;
            _repository.Update(created);

            //check
            var finded = _repository.Find(created.Id.GetValueOrDefault());

            Assert.AreEqual(created.Total, finded.Total);
        }
Exemplo n.º 6
0
        public void UpdateDayPostionNewDayTest(decimal yestarday,
                                               decimal today,
                                               decimal?DayPositionToday)
        {
            //behavior
            var balance = BalanceFactory.Build(x => x.Total = today);


            //test
            balance.UpdateDayPosition(yestarday);

            //assert
            Assert.AreEqual(DayPositionToday, balance.DayPosition);
        }
        public void TestFindOrCreatedDontHaveBalanceOfDay()
        {
            var account = AccountFactory.Create();
            var created = BalanceFactory.Create(x =>
            {
                x.Date    = DateTime.Today;
                x.Account = account;
            });


            var finded = _repository.FindOrCreateBy(account, DateTime.Today);

            //check
            Assert.AreEqual(created.Id, finded.Id);
        }
        public void TestListListTodayMore30Ahead(int input, int output)
        {
            var account = AccountFactory.Create();

            for (int i = 0; i < input; i++)
            {
                BalanceFactory.Create(x =>
                {
                    x.Date    = DateTime.Today.AddDays(i);
                    x.Account = account;
                });
            }
            var balances = _repository.ListTodayMore30Ahead(account.Id);

            //check
            Assert.AreEqual(output, balances.Count);
        }
        public void TestFindOrCreatedDontHaveBalanceOfPreviuslyDay()
        {
            var account = AccountFactory.Create();
            var created = BalanceFactory.Create(x =>
            {
                x.Date    = DateTime.Today.AddDays(-1);
                x.Account = account;
            });


            var finded = _repository.FindOrCreateBy(account, DateTime.Today);

            //check
            Assert.AreNotEqual(created.Id, finded.Id);
            Assert.AreEqual(created.Total, finded.Total);
            Assert.AreEqual(_repository.Count(), 2);
        }
        public void TestToProcess(int numberAccount, int numberBalancesCreated)
        {
            var date = DateTime.Today;

            var accounts = AccountFactory.CreateList(numberAccount);

            foreach (Account account in accounts.GetRange(0, numberBalancesCreated))
            {
                BalanceFactory.Create(x => x.Account = account);
            }

            var result = _repository.ToProcess(date, accounts);


            ////check
            Assert.AreEqual(result.Select(x => x.Id), accounts.Select(x => x.Id));
            Assert.AreEqual(result.Count, accounts.Count);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public void TestGenerateBalanceWithInterestWithNegativeTotal()
        {
            //Input
            var previsulyBalance = BalanceFactory.Create(x =>
            {
                x.Total   = -10.00m;
                x.Charges = new List <ShortEntryDTO>();
            });

            var balance = BalanceFactory.Create(x =>
            {
                x.Total   = -10.00m;
                x.Charges = new List <ShortEntryDTO>();
            });

            var date = DateTime.Now;


            //behavior
            _mockBalanceRepository.Setup(m => m.BeginTransaction())
            .Verifiable();
            _mockBalanceRepository.Setup(m => m.Commit())
            .Verifiable();
            _mockBalanceRepository.Setup(m => m.Update(balance))
            .Verifiable();
            _mockBalanceRepository.Setup(m => m.LastByOrDefault(balance.Account, It.IsAny <DateTime>()))
            .Returns(previsulyBalance);

            _mockInterestRepository.Setup(m => m.Save(It.IsAny <Interest>()));


            //test
            _service.GenerateBalanceWithInterest(balance, date);


            //assert
            Assert.AreEqual(balance.Closed, true);

            _mockBalanceRepository.Verify(x => x.BeginTransaction(), Times.Once());
            _mockBalanceRepository.Verify(x => x.Commit(), Times.Once());
            _mockBalanceRepository.Verify(x => x.Update(balance), Times.Once());
        }
 public CasinoBalanceController(BalanceFactory factory)
 {
     _factory = factory;
 }
Exemplo n.º 14
0
 public BalanceController(BalanceFactory factory)
 {
     _factory       = factory;
     _gameManager   = _factory.GetManagerService(BalanceFactoryType.Game);
     _casinoManager = _factory.GetManagerService(BalanceFactoryType.Casino);
 }
Exemplo n.º 15
0
 public GameBalanceController(BalanceFactory factory)
 {
     _factory = factory;
 }