public void GetBalanceTest()
        {
            var val = _exampleBank.GetBalance(1234567890123456, 123456);

            Assert.AreEqual(val, 1000);

            var val2 = _exampleBank.GetBalance(1111111111111111, 888888);

            Assert.AreEqual(val2, 1500.12);
        }
Esempio n. 2
0
        private void ShowInstanceMenu(IBank sendingBank)
        {
            bool showMenu = true;

            while (showMenu)
            {
                PrintBankOperations(sendingBank);
                bool converted = Int32.TryParse(Console.ReadLine(), out int input);

                if (converted)
                {
                    switch (input)
                    {
                    case 0:
                        showMenu = false;
                        break;

                    case 1:
                        TransactionResult(SendingMoney(sendingBank).Status);
                        break;

                    case 2:
                        Console.WriteLine(sendingBank.GetBalance());
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        public void GetBalance_ShouldGetBalance(string x, double expected)
        {
            // Arrage
            IBank bank = Setup();
            // Act
            double actual = bank.GetBalance(x);

            // assert
            Assert.Equal(expected, actual);
        }
Esempio n. 4
0
        public void Withdraw_SimpleValueShouldWithdraw(string x, int y, bool expected)
        {
            // Arrage
            IBank bank = Setup();
            // Act
            bool actual = bank.Withdraw(x, y);
            bool a      = bank.GetBalance(x) == 1000 - y;

            // assert
            Assert.Equal(expected, actual && a);
        }
Esempio n. 5
0
 public virtual double GetBalance()
 {
     return(_bank.GetBalance());
 }
Esempio n. 6
0
 public void GetBalance()
 {
     _bankOperations.GetBalance();
 }
Esempio n. 7
0
        public void CanGetBalanceForNewlyCreatedAccount()
        {
            _theBank.CreateAccount("David");
            var result = _theBank.GetBalance("David");

            Assert.That(result, Is.EqualTo(0m).Within(0.0000001m));
        }
    public override void Init()
    {
        // no init needed. The following is an example of using the IBank:
        IBank bank = ScenePrivate.FindReflective <IBank>("CoroutineLockExample").FirstOrDefault();

        if (bank != null)
        {
            bank.CreateAccount("bob", 100);
            bank.CreateAccount("sue", 100);
            bank.CreateAccount("joe", 100);

            StartCoroutine(() =>
            {   // Send some money from joe to sue every 0.3 seconds
                while (true)
                {
                    bank.TransferMoney("joe", "sue", 3);
                    Wait(TimeSpan.FromSeconds(0.3));
                }
            });

            StartCoroutine(() =>
            {   // Send some money from sue to bob every 0.1 seconds
                while (true)
                {
                    bank.TransferMoney("sue", "bob", 1);
                    Wait(TimeSpan.FromSeconds(0.1));
                }
            });

            StartCoroutine(() =>
            {   // Send some money from sue to bob every 0.1 seconds
                while (true)
                {
                    bank.TransferMoney("bob", "joe", 2);
                    Wait(TimeSpan.FromSeconds(0.2));
                }
            });

            StartCoroutine(() =>
            {   // Send some money all around
                while (true)
                {
                    bank.TransferMoney("joe", "bob", 10);
                    bank.TransferMoney("joe", "sue", 10);
                    bank.TransferMoney("sue", "bob", 10);
                    bank.TransferMoney("sue", "joe", 10);
                    bank.TransferMoney("bob", "sue", 10);
                    bank.TransferMoney("bob", "joe", 10);
                    Wait(TimeSpan.FromSeconds(0.1));
                }
            });

            // "weekly" reports:
            StartCoroutine(() =>
            {
                while (true)
                {
                    Wait(TimeSpan.FromSeconds(300));
                    // Note that it is possible for transactions to get in between the reporting in here, due to threading.
                    // We aren't actually getting the entire report atomically here.
                    Log.Write($"Balances: Bob={bank.GetBalance("bob")} Sue={bank.GetBalance("sue")} Joe={bank.GetBalance("joe")}");
                }
            });

            // "weekly" atomic reports:
            StartCoroutine(() =>
            {
                while (true)
                {
                    Wait(TimeSpan.FromSeconds(300));
                    // This report is generated inside the lock and so should be atomic: balances should always total 300 in this example.
                    Log.Write(bank.GetReport());
                }
            });
        }
    }