Esempio n. 1
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());
        }
Esempio n. 2
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());
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        /// <summary>
        /// Show the stats of the previous week and month
        /// </summary>
        private void ShowLastMonthAndWeekStats()
        {
            ExpenseController ec = new ExpenseController();

            double monthStats = ec.GetMonthStats();
            double weekStats = ec.GetWeekStats();

            Console.WriteLine("Month stats: {0}", monthStats);
            Console.WriteLine("Week stats: {0}", weekStats);
        }
Esempio n. 5
0
        /// <summary>
        /// The method that will create a new payment
        /// </summary>
        /// <returns>A payment</returns>
        private Payment GetPayment()
        {
            ExpenseController ec = new ExpenseController();
            PaymentMethod method = GetPaymentMethod();
            double amount;

            Console.WriteLine("Insert Amount:");
            while (!double.TryParse(Console.ReadLine(), out amount)) ;

            if (method is Cheque)
            {
                int chequeNumber;
                Console.WriteLine("Insert Cheque Number:");
                while (!int.TryParse(Console.ReadLine(), out chequeNumber)) ;
                return ec.CreatePayment(method, amount, chequeNumber);
            }
            else
            {
                return ec.CreatePayment(method, amount);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// The method that will choose a payment method in the repository
        /// </summary>
        /// <returns>A payment method</returns>
        private PaymentMethod GetPaymentMethod()
        {
            PaymentMethod method = null;
            ExpenseController ec = new ExpenseController();
            PaymentMethodUI pmUI = new PaymentMethodUI();

            int numPayMeth = ec.GetPaymentMethodRepositorySize();
            if (numPayMeth == 0)
            {
                Console.WriteLine("Create a new Payment Method");
                pmUI.ShowRegisterPayment();
                method = ec.GetLastPaymentMethod();
            }
            else
            {
                int option = 999;
                Console.WriteLine("Choose a Payment Method");
                pmUI.List();

                do
                {
                    if (int.TryParse(Console.ReadLine(), out option))
                    {
                        method = ec.GetPaymentMethod(option);
                    }
                    else
                    {
                        option = -1;
                    }
                } while (option < 0 || option > numPayMeth);
            }

            return method;
        }
Esempio n. 7
0
        /// <summary>
        /// The method that will choose a expense type in the repository
        /// </summary>
        /// <returns>A expense type</returns>
        private ExpenseType GetExpenseType()
        {
            ExpenseType type = null;
            ExpenseController ec = new ExpenseController();
            ExpenseTypeUI etUI = new ExpenseTypeUI();

            int numExpType = ec.GetExpenseTypeRepositorySize();
            if (numExpType == 0)
            {
                Console.WriteLine("Create a new Expense Type");
                etUI.ShowRegisterExpenseType();
                type = ec.GetLastExpenseType();
            }
            else
            {
                int option = 999;
                Console.WriteLine("Choose a Expense Type");
                etUI.List();

                do
                {
                    if (int.TryParse(Console.ReadLine(), out option))
                    {
                        type = ec.GetExpenseType(option);
                    }
                    else
                    {
                        option = -1;
                    }
                } while (option < 0 || option > numExpType);
            }

            return type;
        }
Esempio n. 8
0
        /// <summary>
        /// The specific method to the register expense ui
        /// </summary>
        private void ShowRegisterExpense()
        {
            ExpenseController ec = new ExpenseController();

            ExpenseType type = GetExpenseType();
            Payment pay = GetPayment();
            DateTime date = GetDate();
            Console.WriteLine("Insert a description");
            string description = Console.ReadLine();

            ec.RegisterExpense(type, pay, date, description);
        }
Esempio n. 9
0
        /// <summary>
        /// Method that will list all of expenses in repository
        /// </summary>
        private void List()
        {
            ExpenseController ec = new ExpenseController();

            Console.WriteLine(" === Expense List ===");

            List<Expense> expenses = ec.GetAllExpenses();
            int i = 0;
            foreach (Expense item in expenses)
            {
                Console.WriteLine(i);
                Console.WriteLine(item);
                Console.WriteLine("---\n");
                i++;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// List the expenses by category from given month
        /// </summary>
        private void ListByTypeAndMonth()
        {
            int month = 99, year = 99;
            do
            {
                Console.WriteLine("Choose a month.\nPress 0 to exit.");
                int.TryParse(Console.ReadLine(), out month);
            } while (month > 12 || month < 0);

            if (month > 0)
            {
                do
                {
                    Console.WriteLine("Choose a year.\nPress 0 to exit.");
                    int.TryParse(Console.ReadLine(), out year);
                } while (year > DateTime.Now.Year || year < 0);

                if (year > 0)
                {
                    ExpenseTypeController etc = new ExpenseTypeController();
                    List<ExpenseType> expenseTypes = etc.GetAllExpenseTypes();

                    ExpenseController ec = new ExpenseController();
                    foreach (ExpenseType type in expenseTypes)
                    {
                        List<Expense> expenses = ec.GetExpensesByTypeAndMonth(type, month, year);
                        if (expenses.Count > 0)
                        {
                            Console.WriteLine(type.ToString());
                            foreach (Expense exp in expenses)
                            {
                                Console.WriteLine(exp.ToString());
                            }
                        }
                    }
                }

            }
        }
Esempio n. 11
0
        /// <summary>
        /// Show a graph of the expenses by type from a given month
        /// </summary>
        private void GraphByTypeAndMonth()
        {
            int month = 99, year = 99;
            do
            {
                Console.WriteLine("Choose a month.\nPress 0 to exit.");
                int.TryParse(Console.ReadLine(), out month);
            } while (month > 12 || month < 0);

            if (month > 0)
            {
                do
                {
                    Console.WriteLine("Choose a year.\nPress 0 to exit.");
                    int.TryParse(Console.ReadLine(), out year);
                } while (year > DateTime.Now.Year || year < 0);

                if (year > 0)
                {
                    List<string> typeStr = new List<string>();
                    List<double> sums = new List<double>();
                    double max = 0;

                    ExpenseTypeController etc = new ExpenseTypeController();
                    List<ExpenseType> expenseTypes = etc.GetAllExpenseTypes();

                    ExpenseController ec = new ExpenseController();
                    foreach (ExpenseType type in expenseTypes)
                    {
                        List<Expense> expenses = ec.GetExpensesByTypeAndMonth(type, month, year);
                        if (expenses.Count > 0)
                        {
                            typeStr.Add(type.key);
                            double tmpAmount = 0;
                            foreach (Expense exp in expenses)
                            {
                                tmpAmount += exp.payment.amount;   
                            }
                            if (tmpAmount > max)
                            {
                                max = tmpAmount;
                            }

                            sums.Add(tmpAmount);
                        }
                    }

                    for (int i = 0; i < typeStr.Count; i++)
                    {
                        Console.Write(typeStr[i] + "\t");
                        int nrStar = (int)sums[i] * 10 / (int)max;
                        for (int j = 0; j < nrStar; j++)
                        {
                            Console.Write("*");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }