Esempio n. 1
0
        public void CheckBalance()
        {
            BankingContext bankingContext = GetContext <BankingContext>();
            String         account        = bankingContext.GetOptional <String> ("account");

            //Check balance of all the accounts
            if (account == null)
            {
                IList <BalanceInfo> balances = new List <BalanceInfo> ();
                BalanceInfo         balance1 = new BalanceInfo {
                    Balance = bankingContext.GetBalance("100021"),
                    Account = "100021"
                };

                BalanceInfo balance2 = new BalanceInfo {
                    Balance = bankingContext.GetBalance("100023"),
                    Account = "100023"
                };

                balances.Add(balance1);
                balances.Add(balance2);
                bankingContext.Set("balance", balances);
                return;
            }

            //Balance of one single account

            if (!bankingContext.AccountExists(account))
            {
                bankingContext.Fail("INEXISTENT_ACCOUNT");                 //Exit with error
            }
            bankingContext.Set("balance", bankingContext.GetBalance(account));
        }
Esempio n. 2
0
        public override void Captured(object value)
        {
            BankingContext bankingContext = GetContext <BankingContext> ();

            //Here we will validate the pin code, which must be equal to 1234
            //We only recognize the client with Id 0000021
            if (bankingContext.CustomerID == "0000021" && value.ToString() != "1234")
            {
                this.Context.Fail("INVALID_PIN");                  //Fail Execution with INVALID_PIN error code
            }
        }
        public IExecutionContext CreateContext(IServiceInfo serviceInfo, Object contextCreationParam)
        {
            if (contextCreationParam == null)
            {
                throw new Exception("The costumer Id must be passed as the contextCreationParam");
            }

            IExecutionContext context = new BankingContext(contextCreationParam.ToString());

            context.NullToken = "<NULL>";
            return(context);
        }
Esempio n. 4
0
        public void DoTransference()
        {
            BankingContext bankingContext = GetContext <BankingContext>();

            String  destination = bankingContext.Get <String> ("destination");
            String  origin      = bankingContext.Get <String> ("origin");
            decimal amount      = bankingContext.Get <Decimal> ("amount");

            //We assume the origin account exists - we only check the destination
            if (!bankingContext.AccountExists(destination))
            {
                bankingContext.Set("account", origin);
                bankingContext.Fail("INEXISTENT_ACCOUNT");                 //Exit with error
            }

            decimal balance = bankingContext.GetBalance(origin);

            if (balance < amount)
            {
                this.Context.Fail("INSUFFICIENT_FUNDS");                 //Exit with error
            }
            //TODO: Do the transference here
        }