public void AddDebitInDatabase_ShouldReturnDebitDetails() { DateTime date = DateTime.UtcNow; var data = new List <Debit>() { new Debit(1, DateTime.UtcNow.ToString(), 1, "Georgi Georgiev", 7500, "In cheque", 1000), new Debit(2, DateTime.UtcNow.ToString(), 2, "Ivan Ivanov", 5000, "Cash", 500) }.AsQueryable(); var mockSet = new Mock <DbSet <Debit> >(); mockSet.As <IQueryable <Debit> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Debit> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Debit> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Debit> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <banking_dbContext>(); mockContext.Setup(c => c.Debit).Returns(mockSet.Object); var service = new DebitController(mockContext.Object); data.ToList().ForEach(a => service.Add(a)); var debit = service.GetDebitDetails(2).First(); Assert.AreEqual(500, debit.DebAmount); }
//Run when "Save" button is clicked. Get information for the detalis of UserAccount and update them with specified data private void btnSave_Click(object sender, EventArgs e) { Debit debit = new Debit(); { debit.Date = lblDate.Text; debit.AccountNo = Convert.ToDecimal(txtAccNum.Text); debit.Name = txtName.Text; debit.OldBalance = Convert.ToDecimal(txtOldBalance.Text); debit.Mode = comboBox1.SelectedItem.ToString(); debit.DebAmount = Convert.ToDecimal(txtDepositAmount.Text); } debitController.Add(debit); decimal accNo = Convert.ToDecimal(txtAccNum.Text); var accountReciever = accController.Get(accNo).FirstOrDefault(); accController.MakeDebitTransaction(debit.DebAmount, accountReciever); MessageBox.Show($"Успешeно изтеглихте {debit.DebAmount.ToString()}лв. от сметката на {debit.Name}!"); }