Beispiel #1
0
        public void GetLedgers()
        {
            var dictionary = new Dictionary <string, object>();
            var service    = new Mock <IBankLedgerService>();

            service.SetupGet(x => x.DataBase).Returns(dictionary);
            var ledgerService = new LedgerService(service.Object);
            var account       = new Account("testing", "password", "", null);
            var badAccount    = new Account(null, "password", "", null);
            var depLedger     = new Ledger(0, TransactionType.Deposit, 10);
            var withLedger    = new Ledger(0, TransactionType.Withdrawl, 10);

            Assert.Throws <ArgumentException>(() => ledgerService.GetAllLedgers(null));
            Assert.Throws <ArgumentException>(() => ledgerService.GetAllLedgers(badAccount));

            Assert.IsNull(ledgerService.GetAllLedgers(account));

            ledgerService.CreateLedger(account, depLedger);
            ledgerService.CreateLedger(account, withLedger);
            ledgerService.CreateLedger(account, depLedger);
            ledgerService.CreateLedger(account, withLedger);
            ledgerService.CreateLedger(account, depLedger);
            ledgerService.CreateLedger(account, withLedger);

            Assert.AreEqual(6, ledgerService.GetAllLedgers(account).Count);
            ledgerService.CreateLedger(account, depLedger);
            ledgerService.CreateLedger(account, withLedger);
            Assert.AreEqual(8, ledgerService.GetAllLedgers(account).Count);
            Assert.IsTrue(ledgerService.GetAllLedgers(account).Any(x => x.LedgerId == 8));
            Assert.AreEqual(4, ledgerService.GetAllLedgers(account)
                            .Count(x => x.TransactionType == TransactionType.Deposit));
            Assert.AreEqual(4, ledgerService.GetAllLedgers(account)
                            .Count(x => x.TransactionType == TransactionType.Withdrawl));
        }