Beispiel #1
0
        public void AddTransferInDatabase_ShouldReturnTransferDetails()
        {
            DateTime date = DateTime.UtcNow;
            var      data = new List <Transfer>()
            {
                new Transfer(1, DateTime.UtcNow.ToString(), 1, "Georgi Georgiev", 1000, 2),
                new Transfer(2, DateTime.UtcNow.ToString(), 2, "Ivan Ivanov", 100, 1)
            }.AsQueryable();
            var mockSet = new Mock <DbSet <Transfer> >();

            mockSet.As <IQueryable <Transfer> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Transfer> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Transfer> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Transfer> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
            var mockContext = new Mock <banking_dbContext>();

            mockContext.Setup(c => c.Transfer).Returns(mockSet.Object);

            var service = new TransferController(mockContext.Object);

            data.ToList().ForEach(a => service.Add(a));

            var transfer = service.GetTransferDetails(2).First();

            Assert.AreEqual(100, transfer.Balance);
        }
Beispiel #2
0
        //Run when "Transfer" button is clicked. Creates transfer, make operation between accounts and send saves to the database via TransferController.
        private void btnTransfer_Click(object sender, EventArgs e)
        {
            decimal accNo   = Convert.ToDecimal(txtTransferFrom.Text);
            var     accSend = accController.Get(accNo).FirstOrDefault();

            txtName.Text = accSend.Name;
            decimal b1            = Convert.ToDecimal(accSend.Balance);
            decimal totalbal      = Convert.ToDecimal(txtTransfer.Text);
            decimal transferaccNo = Convert.ToDecimal(txtTransferDestination.Text);

            if (b1 > totalbal)
            {
                var accRecieve = accController.Get(transferaccNo).FirstOrDefault();
                accController.MakeTransaction(totalbal, accSend, accRecieve);
                Transfer transfer = new Transfer();
                {
                    transfer.AccountNo  = Convert.ToDecimal(txtTransferFrom.Text);
                    transfer.ToTransfer = Convert.ToDecimal(txtTransferDestination.Text);
                    transfer.Date       = DateTime.UtcNow.ToString();
                    transfer.Name       = txtName.Text;
                    transfer.Balance    = Convert.ToDecimal(txtTransfer.Text);
                }
                transferController.Add(transfer);
                MessageBox.Show($"Успешeно преведохте {transfer.Balance}лв. по сметката на {accRecieve.Name}!");
            }
        }