Пример #1
0
 /// <summary>
 /// The main constructor of the expense
 /// </summary>
 /// <param name="type">expense type</param>
 /// <param name="payment">expense payment</param>
 /// <param name="date">expense date</param>
 /// <param name="description">expense description</param>
 public Expense(ExpenseType type, Payment payment, DateTime date, string description)
 {
     this.type = type;
     this.payment = payment;
     this.date = date;
     this.description = description;
 }
Пример #2
0
        public void TestToString()
        {
            ExpenseType expType1 = new ExpenseType("AAA", "aaa");
            ExpenseType expType2 = new ExpenseType("A1B1", "testes");

            Assert.AreEqual("AAA - aaa", expType1.ToString());
            Assert.AreEqual("A1B1 - testes", expType2.ToString());
        }
Пример #3
0
        public void TestToString()
        {
            ExpenseType type = new ExpenseType("AAA", "aaa");
            Money money1 = new Money("EUR");
            Payment pay1 = new Payment(money1, 15);
            DateTime date = new DateTime(2012, 12, 21, 15, 30, 00);
            Expense exp = new Expense(type, pay1, date, "AAA");


            Assert.AreEqual("Expense:\nDescription: AAA\nType: AAA - aaa\nPayment: Payment: Money\nCurrency: EUR\nAmount: 15\nDate: 21/12/2012 15:30:00", exp.ToString());
        }
Пример #4
0
        public void TestRegisterExpense()
        {
            ExpenseController ec = new ExpenseController();
            ExpenseType type = new ExpenseType("AAA", "aaa");
            Money money1 = new Money("EUR");
            Payment pay1 = new Payment(money1, 15);
            DateTime date = new DateTime(2012, 12, 21, 15, 30, 00);
            ec.RegisterExpense(type, pay1, date, "AAA");
        
            List<Expense> list = PersistenceFactory.GetFactory().GetRepository().GetExpenseRepository().All();

            Assert.AreEqual("Expense:\nDescription: AAA\nType: AAA - aaa\nPayment: Payment: Money\nCurrency: EUR\nAmount: 15\nDate: 21/12/2012 15:30:00", list[0].ToString());
        }
Пример #5
0
        public void TestGetExpensesLastMonth()
        {
            ExpenseController ec = new ExpenseController();
            ExpenseType type = new ExpenseType("AAA", "aaa");
            Money money1 = new Money("EUR");
            Payment pay1 = new Payment(money1, 15);
            DateTime date = new DateTime(2012, 12, 21, 15, 30, 00);
            ec.RegisterExpense(type, pay1, date, "AAA");

            DateTime date1 = DateTime.Now;
            ec.RegisterExpense(type, pay1, date1, "BBB");

            List<Expense> list = ec.GetExpensesFromLastMonth();
            Assert.AreEqual(String.Format("Expense:\nDescription: BBB\nType: AAA - aaa\nPayment: Payment: Money\nCurrency: EUR\nAmount: 15\nDate: {0}", date1), list[0].ToString());
        }
Пример #6
0
        public void TestViewBalance()
        {
            IncomeController ic = new IncomeController();
            IncomeType typeI = new IncomeType("AAA", "aaa");
            DateTime dateI = new DateTime(2012, 12, 21, 15, 30, 00);
            ic.RegisterIncome(typeI, dateI, 25, "AAA");

            ExpenseController ec = new ExpenseController();
            ExpenseType typeE = new ExpenseType("AAA", "aaa");
            Money moneyE = new Money("EUR");
            Payment payE = new Payment(moneyE, 15);
            DateTime dateE = new DateTime(2012, 12, 21, 15, 30, 00);
            ec.RegisterExpense(typeE, payE, dateE, "AAA");

            BalanceController bc = new BalanceController();
            double actual = bc.CalculateBalance();
            Assert.AreEqual(10, actual);
        }
        /// <summary>
        /// The method that will return a list with all expenses from a given month, year and type
        /// </summary>
        /// <param name="type">the expense type</param>
        /// <param name="month">the month</param>
        /// <param name="year">the year</param>
        /// <returns>a list with expenses</returns>
        public List<Expense> GetExpensesByTypeAndMonth(ExpenseType type, int month, int year)
        {
            List<Expense> expRet = new List<Expense>();
            List<Expense> expenses = GetAllExpenses();

            foreach (Expense item in expenses)
            {
                if (item.type.key == type.key && item.date.Year == year && item.date.Month == month)
                {
                    expRet.Add(item);
                }
            }

            return expRet;
        }
        /// <summary>
        /// Method that will save an expense
        /// </summary>
        /// <param name="type">expense type</param>
        /// <param name="payment">expense payment</param>
        /// <param name="date">expense date</param>
        /// <param name="description">expense description</param>
        public void RegisterExpense(ExpenseType type, Payment payment, DateTime date, string description)
        {
            Expense exp = new Expense(type, payment, date, description);

            PersistenceFactory.GetFactory().GetRepository().GetExpenseRepository().Save(exp);
        }
Пример #9
0
        public void TestSumExpenses()
        {
            ExpenseController ec = new ExpenseController();
            ExpenseType type = new ExpenseType("AAA", "aaa");
            Money money1 = new Money("EUR");
            Payment pay1 = new Payment(money1, 15);
            DateTime date = DateTime.Now;
            date.Subtract(new TimeSpan(5, 0, 0, 0));
            ec.RegisterExpense(type, pay1, date, "AAA");

            Payment pay2 = new Payment(money1, 20);
            DateTime date2 = DateTime.Now.Subtract(new TimeSpan(10, 0, 0, 0));
            ec.RegisterExpense(type, pay2, date2, "BBB");

            List<Expense> allExpenses = ec.GetAllExpenses();
            double sum = ec.SumExpenses(allExpenses);

            Assert.AreEqual(35, sum);
        }
Пример #10
0
        public void TestGetWeekStats()
        {
            ExpenseController ec = new ExpenseController();
            ExpenseType type = new ExpenseType("AAA", "aaa");
            Money money1 = new Money("EUR");
            Payment pay1 = new Payment(money1, 15);
            DateTime date = DateTime.Now;
            date.Subtract(new TimeSpan(5, 0, 0, 0));
            ec.RegisterExpense(type, pay1, date, "AAA");

            double amount1 = ec.GetWeekStats();
            Assert.AreEqual(-15, amount1);

            Payment pay2 = new Payment(money1, 20);
            DateTime date2 = DateTime.Now.Subtract(new TimeSpan(10, 0, 0, 0));
            ec.RegisterExpense(type, pay2, date2, "BBB");

            double amount2 = ec.GetWeekStats();
            Assert.AreEqual(5, amount2);
        }
 /// <summary>
 /// Saves an expense type object in the repository
 /// </summary>
 /// <param name="expType">the object of expense type</param>
 public void Save(ExpenseType expType)
 {
     types.Add(expType);
 }
        /// <summary>
        /// The method that will share data between ui, model and persistance
        /// </summary>
        /// <param name="key">the key of expense type</param>
        /// <param name="description">the description of expense type</param>
        public void RegisterExpenseType(string key, string description)
        {
            ExpenseType expType = new ExpenseType(key, description);

            PersistenceFactory.GetFactory().GetRepository().GetExpenseTypeRepository().Save(expType);
        }