private void CreateTransactionHistoryReport(TransactionInfo tranInfo, CardAccount cardAccount)
 {
     automatedTellerMachineContext.TransactionsHistories.Add(new TransactionsHistory()
     {
         Ammount = tranInfo.MoneyToRetrieve,
         TransactionDate = DateTime.Now,
         CardAccount = cardAccount
     });
 }
        public void TestOnTooShortCardNumberShouldThrowArgumentException()
        {
            var tranInfo = new TransactionInfo()
            {
                CardNumber = "SHORT",
                CardPIN = "0000",
                MoneyToRetrieve = 200
            };

            automatedTellerMachine.RetrieveMoney(tranInfo);
        }
        public void TestOnTooLongCardNumberShouldThrowArgumentException()
        {
            var tranInfo = new TransactionInfo()
            {
                CardNumber = "CARD-NUMBER-TOO-LONG",
                CardPIN = "0000",
                MoneyToRetrieve = 200
            };

            automatedTellerMachine.RetrieveMoney(tranInfo);
        }
   public void TestOnExistingCardAccountAndInValidAmountOfMoneyToRetrieveShouldThrowArgumentException()
   {
       var tranInfo = new TransactionInfo()
       {
           CardNumber = "111-11-111",
           CardPIN = "0000",
           MoneyToRetrieve = -200
       };
 
       automatedTellerMachine.RetrieveMoney(tranInfo);
   }
Exemplo n.º 5
0
 private static void PerformTransaction(TransactionInfo tranInfo)
 {
     try
     {
         automatedTellerMachine.RetrieveMoney(tranInfo);
         Console.WriteLine("\rSuccessful transaction!");
     }
     catch (Exception e)
     {
         Console.WriteLine("\r" + e.Message);
     }
 }
        public void RetrieveMoney(TransactionInfo tranInfo)
        {
            using (var transaction = automatedTellerMachineContext.Database.BeginTransaction(IsolationLevel.RepeatableRead))
            {
                try
                {
                    if (!validationController.IsValidCardNumber(tranInfo.CardNumber))
                    {
                        throw new ArgumentException("Invalid card number. Current transaction is aborted!");
                    }

                    if (!validationController.IsValidCardPin(tranInfo.CardPIN))
                    {
                        throw new ArgumentException("Invalid Card PIN Code. Current transaction is aborted!");
                    }

                    var cardAccount = automatedTellerMachineContext.CardAccounts
                                                                   .FirstOrDefault(c => c.CardNumber == tranInfo.CardNumber);

                    if (cardAccount == null)
                    {
                        throw new ArgumentException("There is no Card account with the given Card number. Current transaction is aborted!");
                    }

                    if (!validationController.IsPinCodeMatches(tranInfo.CardPIN, cardAccount.CardPIN))
                    {
                        throw new ArgumentException("Chosen Card PIN Code does not matches the actual PIN Code of the card account. Current transaction is aborted!");
                    }

                    if (!validationController.IsPermittedWithdrawalAmount(tranInfo.MoneyToRetrieve, cardAccount.CardCash))
                    {
                        throw new ArgumentException("Invalid withdrawal money amount to retrieve. Current transaction is aborted!");
                    }

                    cardAccount.CardCash -= tranInfo.MoneyToRetrieve;

                    this.CreateTransactionHistoryReport(tranInfo, cardAccount);

                    transaction.Commit();
                    automatedTellerMachineContext.SaveChanges();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }
        }
        public void TestOnExistingCardAccountAndValidAmountOfMoneyToRetrieve()
        {
            var tranInfo = new TransactionInfo()
            {
                CardNumber = "111-11-111",
                CardPIN = "0000",
                MoneyToRetrieve = 200
            };

            var oldTranHistoryCount = automatedTellerMachineContext.TransactionsHistories.Count();
            var oldCardCash = automatedTellerMachine.GetCardAccountCash(tranInfo.CardNumber);

            automatedTellerMachine.RetrieveMoney(tranInfo);

            var newTranHistoryCount = automatedTellerMachineContext.TransactionsHistories.Count();
            var newCardCash = automatedTellerMachine.GetCardAccountCash(tranInfo.CardNumber);

            Assert.AreEqual(oldTranHistoryCount + 1, newTranHistoryCount);
            Assert.AreEqual(oldCardCash - tranInfo.MoneyToRetrieve, newCardCash);
        }
        public void TestValidUnknownCardNumberShouldThrowArgumentException()
        {
            var tranInfo = new TransactionInfo()
            {
                CardNumber = "111-11-999",
                CardPIN = "0000",
                MoneyToRetrieve = 200
            };

            automatedTellerMachine.RetrieveMoney(tranInfo);
        }
        public void TestOnNullCardPinShouldThrowArgumentException()
        {
            var tranInfo = new TransactionInfo()
            {
                CardNumber = "111-11-111",
                CardPIN = null,
                MoneyToRetrieve = 200
            };

            automatedTellerMachine.RetrieveMoney(tranInfo);
        }