示例#1
0
        static void Main(string[] args)
        {
            IBankAccount bankAccount = DynamicLogger <BankAccount> .As <IBankAccount>();

            bankAccount.Name = "John Smith";

            bankAccount.Deposit(1000);
            bankAccount.Withdraw(50);
            bankAccount.Withdraw(50);
            bankAccount.Withdraw(35);
            bankAccount.Deposit(250);
            bankAccount.Withdraw(20);
            bankAccount.Deposit(3);
            bankAccount.Withdraw(100);
            bankAccount.Withdraw(5);
            bankAccount.Withdraw(50);
            bankAccount.Deposit(100);
            bankAccount.Withdraw(50);
            bankAccount.Deposit(5);
            var createdDate = bankAccount.DateCreated;

            Console.WriteLine("***** Calling ToString() on proxy object *****");
            Console.WriteLine(bankAccount);

            Console.ReadLine();
        }
示例#2
0
        public void GetTransactionListBetweenValidDates()
        {
            ICustomer customer = new Customer(1, "Name", "Address", "Phone", "Email");

            int          accNumber = 1;
            IBankAccount account   = BankAccount.CreateBankAccount(customer, accNumber);

            account.Deposit(1000);
            Thread.Sleep(1000);
            DateTime from = DateTime.Now;

            account.Withdraw(400);
            Thread.Sleep(1000);
            DateTime to = DateTime.Now;

            Thread.Sleep(1000);
            account.Deposit(200);

            Assert.AreEqual(3, account.Transactions.Count);
            IList <ITransaction> result = account.GetTransactions(from, to);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreSame(result[0], account.Transactions[1]);
        }
示例#3
0
        public void Verified_Account_Can_Be_Freezed_Test()
        {
            IBank    bank       = new Bank();
            Currency pln        = new Currency("PLN");
            var      currencies = new List <Currency>();

            currencies.Add(pln);
            Guid         id          = Guid.NewGuid();
            Guid         userId      = Guid.NewGuid();
            IBankAccount bankAccount = bank.CreateBankAccount(id, userId, currencies);

            bankAccount.Deposit(pln, new Money(1m, "PLN"));
            bankAccount.Deposit(pln, new Money(200m, "PLN"));
            bankAccount.Deposit(pln, new Money(300m, "PLN"));
            bankAccount.Deposit(pln, new Money(500m, "PLN"));
            bankAccount.VerifyAccount();
            bankAccount.Deposit(pln, new Money(1000m, "PLN"));
            bankAccount.Deposit(pln, new Money(2000m, "PLN"));
            bankAccount.Withdraw(pln, new Money(100m, "PLN"));
            bankAccount.Deposit(pln, new Money(3000m, "PLN"));
            bankAccount.Withdraw(pln, new Money(100m, "PLN"));
            bankAccount.Deposit(pln, new Money(5000m, "PLN"));
            bankAccount.Withdraw(pln, new Money(100m, "PLN"));

            bankAccount.FreezeAccount();
            Assert.IsTrue(bankAccount.IsFreezed);
            bankAccount.Withdraw(pln, new Money(100m, "PLN"));
            Assert.IsFalse(bankAccount.IsFreezed);
        }
示例#4
0
        public void Money_Can_Be_Withdrawn_Only_If_Was_Verified_Positive_Test()
        {
            IBank    bank       = new Bank();
            Currency pln        = new Currency("PLN");
            var      currencies = new List <Currency>();

            currencies.Add(pln);
            Guid         id          = Guid.NewGuid();
            Guid         userId      = Guid.NewGuid();
            IBankAccount bankAccount = bank.CreateBankAccount(id, userId, currencies);

            Money m100 = new Money(100m, "PLN");
            Money m0   = new Money(0m, "PLN");

            bankAccount.Deposit(pln, m100);
            bankAccount.VerifyAccount();

            try
            {
                bankAccount.Withdraw(pln, m100);
            }
            catch
            {
                Assert.Fail();
                return;
            }

            Assert.AreEqual(bankAccount.GetBalance(pln), new Money(0m, "PLN"));
        }
示例#5
0
 private static void Deposit(decimal amount, IBankAccount account)
 {
     if (account.Deposit(amount))
     {
         Console.WriteLine("Deposit complete: {0:C}", amount);
     }
 }
示例#6
0
        public static void Run()
        {
            IBankAccount account = Aspects.AddAspects <IBankAccount>(new BankAccount());

            account.Deposit(1000);
            account.Withdraw(500);
        }
 public void TransferFunds(IBankAccount account1, IBankAccount account2, int amount)
 {
     _databaseMapper.BeginTransaction();
     account1.Withdraw(amount);
     account2.Deposit(amount);
     _databaseMapper.Dispose();
 }
示例#8
0
 public void TransferFunds(IBankAccount accountOne, IBankAccount accountTwo, int p)
 {
     m_DatabaseManager.BeginTransaction();         
     accountTwo.Deposit(p);
     accountOne.Withdraw(p);            
     m_DatabaseManager.Dispose();        
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="account"></param>
        /// <param name="transferType"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static TransferResult MakeTransfer(IBankAccount account, TransferType transferType, double amount)
        {
            switch (transferType)
            {
            case TransferType.deposit:
                if (amount > account.MaxTransactionLimit)
                {
                    return(TransferResult.MaxTransactionLimitExceeded);
                }

                else
                {
                    account.Deposit(amount);
                    return(TransferResult.TransferOK);
                }
            // return TransferResult.TransferOK;

            case TransferType.withdraw:
                if (amount > account.Balance)
                {
                    return(TransferResult.NotEnoughBalance);
                }
                else
                {
                    account.Withdraw(amount);
                    return(TransferResult.TransferOK);
                }
            }
            return(TransferResult.TransferOK);
        }
        public void MovingFundsUsingTransactions()
        {
            MockRepository   mocks           = new MockRepository();
            IDatabaseManager databaseManager = mocks.StrictMock <IDatabaseManager>();
            IBankAccount     accountOne      = mocks.StrictMock <IBankAccount>(),
                             accountTwo      = mocks.StrictMock <IBankAccount>();

            using (mocks.Ordered())
            {
                Expect.Call(databaseManager.BeginTransaction()).Return(databaseManager);
                using (mocks.Unordered())
                {
                    Expect.Call(accountOne.Withdraw(1000));
                    Expect.Call(accountTwo.Deposit(1000));
                }
                databaseManager.Dispose();
            }

            mocks.ReplayAll();

            Bank bank = new Bank(databaseManager);

            bank.TransferFunds(accountOne, accountTwo, 1000);

            mocks.VerifyAll();
        }
示例#11
0
 public void TransferFunds(IBankAccount accountOne, IBankAccount accountTwo, int p)
 {
     m_DatabaseManager.BeginTransaction();
     accountTwo.Deposit(p);
     accountOne.Withdraw(p);
     m_DatabaseManager.Dispose();
 }
示例#12
0
 private static void Deposit(decimal amount, IBankAccount account)
 {
     if (account.Deposit(amount))
     {
         Console.WriteLine("Deposit complete: {0:C}", amount);
     }
 }
 public void Transfer(IBankAccount from, IBankAccount toAccount, double amount)
 {
     Console.WriteLine("Neft  Started");
     from.Withdraw(amount);
     toAccount.Deposit(amount);
     Console.WriteLine("Neft Completed");
 }
示例#14
0
 public void Transfer(IBankAccount target, int amount)
 {
     lock (this)
     {
         Balance -= amount;
         target.Deposit(amount);
     }
 }
 public void Transfer(IBankAccount from, IBankAccount toAccount, double amount)
 {
     Console.WriteLine("MY Transaction Started");
     from.Withdraw(amount);
     Console.WriteLine("FROM "+from.Balance);
     toAccount.Deposit(amount);
     Console.WriteLine("TO " + toAccount.Balance);
     Console.WriteLine("MY Transaction Started");
 }
示例#16
0
        public void PrintAccountStatment()
        {
            bankAccount.Deposit(1000);
            bankAccount.Withdraw(100); // or -100
            bankAccount.Deposit(500);
            bankAccount.PrintStatement();

            var values = new List <string>();

            writer
            .Setup(x => x.Print(It.IsAny <string>()))
            .Callback <string>((text) => values.Add(text));

            writer.Verify(x => x.Print("DATE       | AMOUNT  | BALANCE"));
            writer.Verify(x => x.Print("10/04/2014 | 500.00  | 1400.00"));
            writer.Verify(x => x.Print("02/04/2014 | -100.00 | 900.00"));
            writer.Verify(x => x.Print("01/04/2014 | 1000.00 | 1000.00"));
        }
示例#17
0
        public void Money_Can_Be_Deposited_To_BankAccount_Any_Time()
        {
            IBank    bank       = new Bank();
            Currency pln        = new Currency("PLN");
            var      currencies = new List <Currency>();

            currencies.Add(pln);
            Guid         id          = Guid.NewGuid();
            Guid         userId      = Guid.NewGuid();
            IBankAccount bankAccount = bank.CreateBankAccount(id, userId, currencies);

            Money m100 = new Money(100m, "PLN");
            Money m0   = new Money(0m, "PLN");

            bankAccount.Deposit(pln, m100);
            bankAccount.Deposit(pln, m100);

            Assert.AreEqual(bankAccount.GetBalance(pln), new Money(200m, "PLN"));
        }
示例#18
0
 private new bool Transfer(double amount, IBankAccount toAccount) //Override this method
 {
     // If Balance – Withdraw is >= 5000 then only transfer can take place.
     // Write the code to achieve the same.
     if (balance - amount >= 5000)
     {
         toAccount.Deposit(amount);
         balance = balance - amount;
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#19
0
        public void When_Account_Is_Closed_Any_Actions_Are_Forbidden_Test()
        {
            IBank    bank       = new Bank();
            Currency pln        = new Currency("PLN");
            var      currencies = new List <Currency>();

            currencies.Add(pln);
            Guid         id          = Guid.NewGuid();
            Guid         userId      = Guid.NewGuid();
            IBankAccount bankAccount = bank.CreateBankAccount(id, userId, currencies);

            bankAccount.Deposit(pln, new Money(1m, "PLN"));
            bankAccount.Deposit(pln, new Money(200m, "PLN"));
            bankAccount.Deposit(pln, new Money(300m, "PLN"));
            bankAccount.Deposit(pln, new Money(500m, "PLN"));
            bankAccount.VerifyAccount();
            bankAccount.Deposit(pln, new Money(1000m, "PLN"));
            bankAccount.Deposit(pln, new Money(2000m, "PLN"));
            bankAccount.Withdraw(pln, new Money(100m, "PLN"));
            bankAccount.Deposit(pln, new Money(3000m, "PLN"));
            bankAccount.Withdraw(pln, new Money(100m, "PLN"));
            bankAccount.Deposit(pln, new Money(5000m, "PLN"));
            bankAccount.Withdraw(pln, new Money(100m, "PLN"));

            bankAccount.CloseAccount();

            try
            {
                bankAccount.GetBalance(pln);
            }
            catch
            {
                Assert.IsTrue(true);
                return;
            }

            Assert.Fail();
        }
        public void TransferAmount(int accountNumber1, int accountNumber2, double amount)
        {
            IBankAccount acc1 = accountsRepo.GetByID(accountNumber1);
            IBankAccount acc2 = accountsRepo.GetByID(accountNumber2);

            // accounts must exist
            if (acc1 == null || acc2 == null)
            {
                throw new ArgumentException("Non-Existing account number");
            }
            // amount to transfer must not be negative
            if (amount < 0)
            {
                throw new ArgumentException("Amount to transfer cannot be negative");
            }

            acc1.Withdraw(amount);
            acc2.Deposit(amount);
            accountsRepo.Update(acc1);
            accountsRepo.Update(acc2);
        }
示例#21
0
        // [ExpectedException(typeof(ArgumentException))]
        public void DepositNegativeAmountExpectArgumentException()
        {
            ICustomer customer = new Customer(1, "Name", "Address", "Phone", "Email");

            int          accNumber      = 1;
            double       initialBalance = 123.45;
            IBankAccount account        = BankAccount.CreateBankAccount(customer, accNumber, initialBalance);

            double amount = -23.45;

            try
            {
                account.Deposit(amount);
                Assert.Fail("Deposit of a negative amount");
            }
            catch (ArgumentException)
            {
                Assert.AreEqual(initialBalance, account.Balance);
                Assert.AreEqual(0, account.Transactions.Count);
            }
        }
示例#22
0
        public void DepositPositiveAmount()
        {
            ICustomer customer = new Customer(1, "Name", "Address", "Phone", "Email");

            int          accNumber      = 1;
            double       initialBalance = 123.45;
            IBankAccount account        = BankAccount.CreateBankAccount(customer, accNumber, initialBalance);

            double amount = 23.45;

            DateTime before = DateTime.Now;

            account.Deposit(amount);

            Assert.AreEqual(initialBalance + amount, account.Balance);
            Assert.AreEqual(1, account.Transactions.Count);
            ITransaction t = account.Transactions[0];

            Assert.AreEqual(1, t.Id);
            Assert.IsTrue(before <= t.DateTime);
            Assert.IsTrue(DateTime.Now >= t.DateTime);
            Assert.AreEqual("Deposit", t.Message);
            Assert.AreEqual(amount, t.Amount);
        }
 public void Deposit(int amount)
 {
     _bankAccount.Deposit(amount, _calendarWrapper.GeteDate());
 }
示例#24
0
        public void Deposit(int accountNumber, int amount)
        {
            IBankAccount bankAccount = bank.GetBankAccount(accountNumber);

            bankAccount.Deposit(amount);
        }
示例#25
0
        public void ProcessProfit(IProfitStrategy profitStrategy)
        {
            double profit = profitStrategy.CalculateProfit(_car);

            _bankAccount.Deposit(profit);
        }
示例#26
0
 public void Transfer(IBankAccount from, IBankAccount to, decimal amount)
 {
     from.Withdraw(amount);
     to.Deposit(amount);
 }
示例#27
0
 private void TransferDC(int index, double amount, out IBankAccount toAc)
 {
     toAc = currentAccount.CheckingList[index];
     toAc.Deposit(amount);
 }
示例#28
0
 private void TransferDB(int index, double amount, out IBankAccount toAc)
 {
     toAc = currentAccount.BusinessList[index];
     toAc.Deposit(amount);
 }