コード例 #1
0
        public void TestFindExistentEntity()
        {
            var created = BalanceFactory.Create();
            var finded  = _repository.Find(created.Id.GetValueOrDefault());

            Assert.AreEqual(created.Id, finded.Id);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
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());
        }