public void shouldCheckExpenseAmountIsPositiveNumber()
 {
     ExpenseRepository repository = new ExpenseRepository();
     var interaction = new AddExpenseInteraction<RAMRepository.ExpenseRepository>(new Interactions.RequestModels.AddExpense { Amount = -44.56, Category = ExpenseCategory}, repository);
     interaction.performAction();
     var response = interaction.ResponseModel;
     Assert.IsTrue(response.Error.HasValue);
     Assert.AreEqual<Interactions.ResponseModels.Error.Codes>(response.Error.Value.Code, Interactions.ResponseModels.Error.Codes.EXPENSE_AMOUNT_MUST_BE_POSITIVE);
 }
 public void shouldCheckExpenseCategoryExists()
 {
     ExpenseRepository repository = new ExpenseRepository();
     var interaction = new AddExpenseInteraction<RAMRepository.ExpenseRepository>(new Interactions.RequestModels.AddExpense { Amount = ExpenseAmount, Category = ExpenseCategory}, repository);
     interaction.performAction();
     var response = interaction.ResponseModel;
     Assert.IsTrue(response.Error.HasValue);
     Assert.AreEqual<Interactions.ResponseModels.Error.Codes>(response.Error.Value.Code, Interactions.ResponseModels.Error.Codes.CATEGORY_DOES_NOT_EXIST);
 }
 public void shouldCheckForInvalidRange()
 {
     ExpenseRepository repository = new ExpenseRepository();
     ListExpenses request = new ListExpenses { From = DateTime.Today.Date, To = DateTime.Today.Date.AddDays(-1) };
     
     var interaction = new ListExpensesInteraction<RAMRepository.ExpenseRepository>(request, repository);
     interaction.performAction();
     var response = interaction.ResponseModel;
     Assert.IsTrue(response.Error.HasValue);
     Assert.AreEqual(Error.Codes.DATE_RANGE_INVALID, response.Error.Value.Code);
 }
        public void shouldAddExpenseToSystemWithCurrentDate()
        { 
            // Add category manully
            CategoryRepository categoryRepository = new CategoryRepository();
            categoryRepository.Add(new Entities.Category { Name = ExpenseCategory });


            ExpenseRepository repository = new ExpenseRepository();
            var interaction = new AddExpenseInteraction<RAMRepository.ExpenseRepository>(new Interactions.RequestModels.AddExpense { Amount = ExpenseAmount, Category = ExpenseCategory}, repository);
            interaction.performAction();
            var response = interaction.ResponseModel;
            Assert.IsFalse(response.Error.HasValue);
            Entities.Expense expense = repository.GetExpenseById(response.Id);
            Assert.IsNotNull(expense);
            Assert.AreEqual<DateTime>(expense.Date, DateTime.Today.Date);
        }
        public void shouldGetAllExpensesSortedByCategory()
        {
            ExpenseRepository repository = new ExpenseRepository();
            SummarizeExpenses request = new SummarizeExpenses { From = DateTime.Today.Date, To = DateTime.Today.Date.AddDays(6) };
            
            var interaction = new SummarizeExpensesInteraction<RAMRepository.ExpenseRepository>(request, repository);
            interaction.performAction();
            var response = interaction.ResponseModel;
            Assert.IsFalse(response.Error.HasValue);

            Dictionary<string, double> summary = response.Expenses;

            Assert.AreEqual(summary.Count, 3);
            Assert.AreEqual(summary[gasCategory.Name], gas0.Amount + gas1.Amount);
            Assert.AreEqual(summary[foodCategory.Name], food0.Amount + food1.Amount);
            Assert.AreEqual(summary[gymCategory.Name], gym0.Amount + gym1.Amount);
        }
        public void initialize()
        {
            RAMRepository.RAMRepository.SharedInstance.Expenses.Clear();
            // Create categories manually
            CategoryRepository categoryRepository = new CategoryRepository();
            categoryRepository.Add(gasCategory);
            categoryRepository.Add(foodCategory);
            categoryRepository.Add(gymCategory);

            // Create expenses manually
            ExpenseRepository expenseRepository = new ExpenseRepository();
            gas0.ExpenseId = expenseRepository.Add(gas0);
            gas1.ExpenseId = expenseRepository.Add(gas1);
            food0.ExpenseId = expenseRepository.Add(food0);
            food0.ExpenseId = expenseRepository.Add(food1);
            gym0.ExpenseId = expenseRepository.Add(gym0);
            gym1.ExpenseId = expenseRepository.Add(gym1);
        }
        public void shouldGetAllExpenses()
        {
            ExpenseRepository repository = new ExpenseRepository();
            ListExpenses request = new ListExpenses { From = DateTime.Today.Date, To = DateTime.Today.Date.AddDays(6) };
            
            var interaction = new ListExpensesInteraction<RAMRepository.ExpenseRepository>(request, repository);
            interaction.performAction();
            var response = interaction.ResponseModel;
            Assert.IsFalse(response.Error.HasValue);

            var expenses = response.Expenses.Select(x => new Expense() { Amount = x.Amount, Date = x.Date, Category = new Category() { Name = x.Category}, ExpenseId = x.ExpenseId }).ToList();

            Assert.AreEqual(expenses.Count, 6);
            Assert.IsTrue(expenses.Contains(gas0));
            Assert.IsTrue(expenses.Contains(gas1));
            Assert.IsTrue(expenses.Contains(food0));
            Assert.IsTrue(expenses.Contains(food1));
            Assert.IsTrue(expenses.Contains(gym0));
            Assert.IsTrue(expenses.Contains(gym1));
        }