public void Can_Retrieve_All_Expenses_From_Database()
 {
     using (var repo = new ExpenseRepository(_context))
     {
         _context.Staffs.Add(sampleManager);
         _context.SaveChanges();
         var staff = _context.Staffs.Single();
         repo.Create(new Expense("E1", 2000, staff.Id));
         repo.Create(new Expense("E2", 32000, staff.Id));
         var allExpenses = repo.GetAllExpenses();
         Assert.AreEqual(2, allExpenses.Count);
     }
 }
Exemple #2
0
        public async Task <IActionResult> Create([FromBody] CreateExpenseReq req)
        {
            var expense = req.toEntity();
            await expenseRepo.Create(expense);

            return(Created($"/api/expenses/${expense.Id}", expense));
        }
        public void Can_Delete_Saved_Expense_From_DataBase()
        {
            using (var repo = new ExpenseRepository(_context))
            {
                _context.Staffs.Add(sampleManager);
                _context.SaveChanges();
                var staff = _context.Staffs.Single();
                repo.Create(new Expense("E1", 2000, staff.Id));
                repo.Create(new Expense("E2", 2000, staff.Id));
                Assert.IsTrue(_context.Expenses.Count() == 2);

                Expense expense = _context.Expenses.First();
                repo.Delete(expense.Id);

                Assert.AreEqual(1, _context.Expenses.Count());
            }
        }
        public void Create(Expense newExpense)
        {
            Contract.Requires <ArgumentNullException>(newExpense != null, "The expense must not be null");
            Contract.Requires <ArgumentNullException>(newExpense.CategoryId > 0, "There must be a category selected");
            Contract.Requires <ArgumentNullException>(newExpense.PaymentMethodId > 0, "There must be a payment method selected");

            _repository.Create(newExpense);
        }
Exemple #5
0
        public void Create(Expense newExpense)
        {
            Contract.Requires <ArgumentNullException>(newExpense != null, "The expense must not be null");
            // ReSharper disable once PossibleNullReferenceException
            Contract.Requires <ArgumentException>(newExpense.CategoryId > 0, "There must be a category selected");
            Contract.Requires <ArgumentException>(newExpense.PaymentMethodId > 0, "There must be a payment method selected");

            _repository.Create(newExpense);
        }
 public void Can_Edit_Saved_Expenses()
 {
     using (var repo = new ExpenseRepository(_context))
     {
         _context.Staffs.Add(sampleManager);
         _context.SaveChanges();
         var staff = _context.Staffs.Single();
         repo.Create(new Expense("E1", 2000, staff.Id));
         Expense expense = _context.Expenses.Single();
         expense.Description = "Test_Expenditure";
         expense.Cost        = 45000;
         repo.Update(expense);
         Assert.IsNotNull(_context.Expenses.Where(x => x.Description == "Test_Expenditure").Single());
     }
 }
 public void Can_Save_New_Expense_To_Database()
 {
     using (var repo = new ExpenseRepository(_context))
     {
         _context.Staffs.Add(sampleEmployee);
         _context.SaveChanges();
         Expense staffExpense = new Expense
                                (
             "Unitest_Expenses",
             32000,
             sampleEmployee.Id
                                );
         repo.Create(staffExpense);
         Expense dbExpense = _context.Expenses.Single();
         Assert.AreEqual("Unitest_Expenses", dbExpense.Description);
     }
 }
        public void Can_Retrieve_Saved_Expense_From_Database()
        {
            using (var repo = new ExpenseRepository(_context))
            {
                _context.Staffs.Add(sampleEmployee);
                _context.SaveChanges();
                Expense staffExpense = new Expense
                                       (
                    "Unitest_Expenses",
                    30000,
                    sampleEmployee.Id
                                       );

                repo.Create(staffExpense);
                Expense savedExpense = repo.GetExpense(_context.Expenses.Single().Id);
                Assert.AreEqual("Unitest_Expenses", savedExpense.Description);
            }
        }
Exemple #9
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if (Double.TryParse(price.Text, out double amount))
            {
                Category currentCategory = categoryRepository.GetItems().Find(c => c.Name == category);

                Expense expense = new Expense();
                expense.CategoryId    = currentCategory.Id;
                expense.AmountOfMoney = Double.Parse(price.Text);
                expense.Date          = date;
                expense.UserId        = controller.user.Id;

                expenseRepository.Create(expense);

                expensePage.UpdateProgressBar();
                this.Close();
            }
            else
            {
                MessageBox.Show("Wrong price entered.");
            }
        }
        /// <summary>
        /// Add new expense in custom user's category to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            // Checks if custom category was selected
            if (customCategories.SelectedIndex >= 0)
            {
                // Validation for field mainText (it is where price was entered)
                if (Double.TryParse(mainText.Text, out double amount))
                {
                    // Adding to database
                    CategoryRepository categories = new CategoryRepository();
                    Category           cat        = categories.GetItems().Find(c => c.Name == customCategories.Items[customCategories.SelectedIndex].ToString());

                    Expense expense = new Expense
                    {
                        CategoryId    = cat.Id,
                        AmountOfMoney = amount,
                        Date          = date,
                        UserId        = controller.user.Id
                    };

                    ExpenseRepository repository = new ExpenseRepository();
                    repository.Create(expense);

                    // Updating progress bar
                    expensePage.SetProgressBar(date);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Wrong price entered");
                }
            }
            else
            {
                MessageBox.Show("Choose category from menu first.");
            }
        }
Exemple #11
0
        public void Create(ExpenseDTO item)
        {
            Expense expense = _mapper.Map <Expense>(item);

            repository.Create(expense);
        }
Exemple #12
0
 public void Create(Expense newExpense)
 {
     _repository.Create(newExpense);
 }
Exemple #13
0
 public ActionResult create(Expense exp)
 {
     _rep.Create(exp);
     return(RedirectToAction(""));
 }