public void BuyCoins_ValidValue() { ModelStateDictionary modelState = new ModelStateDictionary(); User user = new User { Email = "*****@*****.**", FirstName = "Amir", LastName = "Akobirovich", MiddleName = "Rofeev", Login = "******", Money = 0, Password = "******", RepeatPassword = "******", WalletID = "WalletID" }; double sendMoney = 143.3; IBlockChainService blockChainService = new BlockChainService(new ModelStateWrapper(modelState), new BlockChainRepository()); BlockChain blockChain = BlockChain.Instance(blockChainService); MoneySend moneySend = new MoneySend { Amount = sendMoney, UserName = user.Login, WalletId = user.WalletID }; blockChain.BuyCoins(moneySend); Thread.Sleep(35000); Assert.AreEqual(blockChain.GetBalanceOfUser(user), sendMoney); }
public void GetBalanceOfUser_MultyValidValue() { ModelStateDictionary modelState = new ModelStateDictionary(); IBlockChainService blockChainService = new BlockChainService(new ModelStateWrapper(modelState), new BlockChainRepository()); BlockChain blockChain = BlockChain.Instance(blockChainService); var users = new User[100]; for (int i = 0; i < users.Length; i++) { users[i] = new User { Email = "*****@*****.**", FirstName = "Amir", LastName = "Akobirovich", MiddleName = "Rofeev", Login = new Random().GetHashCode().ToString(), Money = 0, Password = "******", RepeatPassword = "******", WalletID = "WalletID" }; } var usersActions = new Task[100]; for (int i = 0; i < users.Length; i++) { Task.Run(() => { MoneySend moneySend = new MoneySend { Amount = 100, UserName = users[i].Login, WalletId = users[i].WalletID }; blockChain.BuyCoins(moneySend); blockChain.AddTransaction(new Transactions { Amount = 50, DateTime = DateTime.Now, FromUser = users[i].Login, ToUser = "******", TransactionID = 12 }); }).Wait(); } Thread.Sleep(35000); foreach (var user in users) { Assert.AreNotEqual(blockChain.GetBalanceOfUser(user), 0); } }
public ActionResult FullMoney(MoneySend sendMoney) { User user = new CurrentUser(new ModelStateWrapper(ModelState)).GetCurrentUser(User.Identity.Name); if (user != null) { sendMoney.UserName = user.Login; _blockChain.BuyCoins(sendMoney); } return(View(new MoneySend { UserName = user.FirstName, Amount = _blockChain.GetBalanceOfUser(user) })); }
public void TransactionsHistory_ValidValues() { bool workProccess = false; IBlockChainRepository blockChainRepository = new BlockChainRepository(); ModelStateDictionary modelState = new ModelStateDictionary(); IBlockChainService blockChainService = new BlockChainService(new ModelStateWrapper(modelState), blockChainRepository); BlockChain blockChain = BlockChain.Instance(blockChainService); User user = new User { Email = "*****@*****.**", FirstName = "Amir", LastName = "Akobirovich", MiddleName = "Rofeev", Login = "******", Money = 0, Password = "******", RepeatPassword = "******", WalletID = "WalletID" }; blockChain.AddTransaction(new Transactions { Amount = 1231, DateTime = DateTime.Now, FromUser = user.Login, ToUser = "******", TransactionID = 13 }); blockChain.AddTransaction(new Transactions { Amount = 32, DateTime = DateTime.Now, FromUser = "******", ToUser = user.Login, TransactionID = 14 }); MoneySend moneySend = new MoneySend { Amount = 100, UserName = user.Login, WalletId = user.WalletID }; blockChain.BuyCoins(moneySend); Thread.Sleep(35000); IEnumerable <Transactions> transactionsHistory = blockChain.TransactionsHistory(user); foreach (var transaction in transactionsHistory) { workProccess = Equals(transaction.FromUser, user.Login) || Equals(transaction.ToUser, user.Login); } Assert.IsTrue(workProccess); }
public void BuyCoins_MultyValidValue() { ModelStateDictionary modelState = new ModelStateDictionary(); var users = new User[100]; var usersAction = new Task[100]; double sendMoney = 143.3; for (int i = 0; i < users.Length; i++) { users[i] = new User { Email = "*****@*****.**", FirstName = "Amir", LastName = "Akobirovich", MiddleName = "Rofeev", Login = new Random().GetHashCode().ToString(), Money = 0, Password = "******", RepeatPassword = "******", WalletID = "WalletID" }; } IBlockChainService blockChainService = new BlockChainService(new ModelStateWrapper(modelState), new BlockChainRepository()); BlockChain blockChain = BlockChain.Instance(blockChainService); for (int i = 0; i < users.Length; i++) { Task.Run(() => { MoneySend moneySend = new MoneySend { Amount = sendMoney, UserName = users[i].Login, WalletId = users[i].WalletID }; blockChain.BuyCoins(moneySend); }).Wait(); } Thread.Sleep(35000); foreach (var user in users) { Assert.AreEqual(blockChain.GetBalanceOfUser(user), sendMoney); } }
public void GetBalanceOfUser_ValidValue() { ModelStateDictionary modelState = new ModelStateDictionary(); User user = new User { Email = "*****@*****.**", FirstName = "Amir", LastName = "Akobirovich", MiddleName = "Rofeev", Login = "******", Money = 0, Password = "******", RepeatPassword = "******", WalletID = "WalletID" }; double predictableBalanceOfUser = 0; IBlockChainService blockChainService = new BlockChainService(new ModelStateWrapper(modelState), new BlockChainRepository()); BlockChain blockChain = BlockChain.Instance(blockChainService); MoneySend moneySend = new MoneySend { Amount = 100, UserName = user.Login, WalletId = user.WalletID }; blockChain.BuyCoins(moneySend); predictableBalanceOfUser = 100; blockChain.AddTransaction(new Transactions { Amount = 50, DateTime = DateTime.Now, FromUser = user.Login, ToUser = "******", TransactionID = 12 }); predictableBalanceOfUser -= 50; Thread.Sleep(35000); Assert.AreEqual(blockChain.GetBalanceOfUser(user), predictableBalanceOfUser); }
public void TransactionsHistory_MultyValidValues() { bool workProccess = false; IBlockChainRepository blockChainRepository = new BlockChainRepository(); ModelStateDictionary modelState = new ModelStateDictionary(); IBlockChainService blockChainService = new BlockChainService(new ModelStateWrapper(modelState), blockChainRepository); BlockChain blockChain = BlockChain.Instance(blockChainService); var users = new User[100]; for (int i = 0; i < users.Length; i++) { users[i] = new User { Email = "*****@*****.**", FirstName = "Amir", LastName = "Akobirovich", MiddleName = "Rofeev", Login = new Random().GetHashCode().ToString(), Money = 0, Password = "******", RepeatPassword = "******", WalletID = "WalletID" }; } var usersActions = new Task[100]; for (int i = 0; i < users.Length; i++) { Task.Run(() => { blockChain.AddTransaction(new Transactions { Amount = 1231, DateTime = DateTime.Now, FromUser = users[i].Login, ToUser = "******", TransactionID = 13 }); blockChain.AddTransaction(new Transactions { Amount = 32, DateTime = DateTime.Now, FromUser = "******", ToUser = users[i].Login, TransactionID = 14 }); MoneySend moneySend = new MoneySend { Amount = 100, UserName = users[i].Login, WalletId = users[i].WalletID }; blockChain.BuyCoins(moneySend); }).Wait(); } Thread.Sleep(35000); foreach (var user in users) { IEnumerable <Transactions> transactionsHistory = blockChain.TransactionsHistory(user); foreach (var transaction in transactionsHistory) { workProccess = Equals(transaction.FromUser, user.Login) || Equals(transaction.ToUser, user.Login); } } Assert.IsTrue(workProccess); }