Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
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)
            }));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public ActionResult SendMoney(MoneySend moneySend)
        {
            CurrentUser currentUser = new CurrentUser(new ModelStateWrapper(ModelState));
            User        FromUser    = currentUser.GetCurrentUser(User.Identity.Name);
            User        ToUser      = _serviceUsers.ListUsers.Where(u => u.WalletID == moneySend.WalletId).FirstOrDefault();

            if (ToUser != null && ToUser.WalletID != FromUser.WalletID)
            {
                FromUser.Money = _blockChain.GetBalanceOfUser(FromUser);

                if (FromUser.Money >= moneySend.Amount)
                {
                    Transactions transactions = new Transactions
                    {
                        DateTime = DateTime.Now,
                        Amount   = moneySend.Amount,
                        FromUser = FromUser.Login,
                        ToUser   = ToUser.Login
                    };

                    _blockChain.AddTransaction(transactions);
                    moneySend = new MoneySend {
                        UserName = FromUser.FirstName, Amount = _blockChain.GetBalanceOfUser(FromUser)
                    };
                }
                else
                {
                    ModelState.AddModelError("WalletId", "У вас на счету недостаточно денег!");
                }
            }
            else
            {
                ModelState.AddModelError("WalletId", "К сожелению такого аккаунта нет в базе или вы указали хеш своего же аккаунта.");
            }

            return(View(moneySend));
        }
Ejemplo n.º 8
0
 public void BuyCoins(MoneySend moneySend)
 {
     _blockChainService.PendingTransactions.Add(new Transactions {
         Amount = moneySend.Amount, DateTime = DateTime.Now, FromUser = "******", ToUser = moneySend.UserName
     });
 }
Ejemplo n.º 9
0
        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);
        }