Beispiel #1
0
        public void AddContentTest()
        {
            // Arrange.
            var text     = "Hello world";
            var chain    = new Chain();
            var login    = "******";
            var password = "******";

            // Act.
            chain.AddContent(text);
            chain.AddUser(login, password);

            // Assert.
            Assert.IsTrue(chain.CheckCorrect());
        }
Beispiel #2
0
        private void CreateNewBlock(object sender, EventArgs e)
        {
            if (curUser == sessionUser)
            {
                return;
            }

            if (curUser == null)
            {
                MessageBox.Show("Выберите пользователя для транзакции!");
                return;
            }
            if (curText == string.Empty)
            {
                MessageBox.Show("Введите текст транзакции!");
                return;
            }
            if (curMoney > sessionUser.Money)
            {
                MessageBox.Show("Недостаточно средств для перевода!");
                return;
            }

            var block = _chain.AddContent(curUser, curText, curMoney);

            curPanel.Controls[0].Text = block.Hash;
            (curPanel.Controls[1] as MetroFramework.Controls.MetroTextBox).ReadOnly = true;

            foreach (Control item in curPanel.Controls)
            {
                if (item.Name == "button")
                {
                    curPanel.Controls.Remove(item);
                    break;
                }
            }
            foreach (Control item in curPanel.Controls)
            {
                if (item.Name == "cmbUser")
                {
                    curPanel.Controls.Remove(item);
                    break;
                }
            }
            foreach (Control item in curPanel.Controls)
            {
                if (item.Name == "txtMoney")
                {
                    curPanel.Controls.Remove(item);
                    break;
                }
            }

            var txtUser = new MetroFramework.Controls.MetroTextBox
            {
                //Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top),
                Text     = block.UserFrom.Login,
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtUser.Width, Height = GetSizeTxtUser.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtUser.X, GetLocationTxtUser.Y)
            };

            curPanel.Controls.Add(txtUser);

            var txtMoney = new MetroFramework.Controls.MetroTextBox
            {
                Anchor = (AnchorStyles.Left | AnchorStyles.Bottom),
                Text   = block.Money.ToString() + " $",
                Size   = new System.Drawing.Size()
                {
                    Width = GetSizeTxtMoney.Width, Height = GetSizeTxtMoney.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtMoney.X, GetLocationTxtMoney.Y)
            };

            curPanel.Controls.Add(txtMoney);

            var txtDateTime = new MetroFramework.Controls.MetroTextBox
            {
                //Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top),
                Text     = block.CreatedOn.ToString(),
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtDateTime.Width, Height = GetSizeTxtDateTime.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtDateTime.X, GetLocationTxtDateTime.Y)
            };

            curPanel.Controls.Add(txtDateTime);

            var txtPrevHash = new TextBox
            {
                Text     = block.PreviousHash,
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtHash.Width, Height = GetSizeTxtHash.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtPrevHash.X, GetLocationTxtPrevHash.Y)
            };

            curPanel.Controls.Add(txtPrevHash);
            curLocation = new Point(curPanel.Location.X + curPanel.Width + OFFSET, curPanel.Location.Y);

            curText = string.Empty;
            AddNewPanel();
            UpdateMyMoney();
            this.Refresh();
        }