Ejemplo n.º 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;
 }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
0
        public void TestToString()
        {
            Money money1 = new Money("EUR");
            Payment pay1 = new Payment(money1, 15);
            Assert.AreEqual("Payment: Money\nCurrency: EUR\nAmount: 15", pay1.ToString());

            DebitCard dc1 = new DebitCard("AAA", "123A", "Me", new DateTime(2013, 07, 1), 157568);
            Payment pay2 = new Payment(dc1, 53.5);
            Assert.AreEqual("Payment: Debit Card\nCard Name: AAA\nCard Number: 157568\nOwner: Me\nBank: 123A\nValidity: 2013/7\nAmount: 53,5", pay2.ToString());

            CreditCard cc1 = new CreditCard("AA", "hi", "Me", new DateTime(2012, 12, 1), 1165131, 15);
            Payment pay3 = new Payment(cc1, 125);
            Assert.AreEqual("Payment: Credit Card\nCard Name: AA\nCard Number: 1165131\nOwner: Me\nBank: hi\nValidity: 2012/12\nLimit: 15\nAmount: 125", pay3.ToString());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Bootstrapper for the expense
        /// </summary>
        private void ExpenseBoot()
        {
            List<ExpenseType> types = PersistenceFactory.GetFactory().GetRepository().GetExpenseTypeRepository().All();
            List<PaymentMethod> methods = PersistenceFactory.GetFactory().GetRepository().GetPaymentMethodRepository().All();
            IExpenseRepository repo = PersistenceFactory.GetFactory().GetRepository().GetExpenseRepository();

            Payment pay1 = new Payment(methods[0], 15);
            repo.Save(new Expense(types[0], pay1, new DateTime(2013, 12, 30, 15, 30, 00), "MacDonalds"));

            PaymentCheque pay2 = new PaymentCheque(methods[2], 23, 1257);
            repo.Save(new Expense(types[2], pay2, new DateTime(2013, 08, 03, 10, 58, 00), "Soccer"));

            repo.Save(new Expense(types[2], pay2, new DateTime(2014, 01, 19, 10, 58, 00), "Soccer 2"));
        }
        /// <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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }