Beispiel #1
0
        public void Can_Create_Account()
        {
            var customer = _bank.Customers.FirstOrDefault(a => a.Id == 1092);
            var account  = _bank.CreateAccount(customer, 1000);

            Assert.Equal("true", account);
        }
Beispiel #2
0
        private IPOExchangeInstitution CreateExchange(IEnumerable <IndividualUser> users, IEnumerable <Company> companies)
        {
            IBank bank = Injector.Get <IBank>();

            var exchangeUsers = new List <IExchangeUser>();

            exchangeUsers.AddRange(users);
            exchangeUsers.AddRange(companies.Select(company => company.GetExchangeUser()));

            foreach (IExchangeUser exchangeUser in exchangeUsers)
            {
                bank.CreateAccount(exchangeUser);
            }
            // Банк как участник биржи
            exchangeUsers.Add(bank.GetExchangeUser());
            Injector.Get <IExchangeUserStorage>().Save((ExchangeUserBase)bank.GetExchangeUser());

            var exchange = new IPOExchangeInstitution(bank, exchangeUsers, companies);

            return(exchange);
        }
    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());
                }
            });
        }
    }
Beispiel #4
0
        public void CanCreateABalance()
        {
            _theBank.CreateAccount("David");
            var result = _theBank.AccountExists("David");

            Assert.That(result, Is.EqualTo(true));
        }
Beispiel #5
0
        public void CreateNewAccount_IsSuccessful()
        {
            // Arrange
            var loginName      = "TestUser1";
            var password       = "******";
            var initialDeposit = 1000;

            // Act
            var newAccount = bank.CreateAccount(loginName, password, initialDeposit);

            // Assert
            Assert.IsNotNull(newAccount, "Account is null.");
            Assert.AreEqual(loginName, newAccount.LoginName);
            Assert.AreEqual(password, newAccount.Password);
            Assert.AreEqual(initialDeposit, newAccount.Balance);
        }