예제 #1
0
        public void CanSerialize()
        {
            var budgetType       = BudgetType.Income_Salary;
            var budgetTypeString = BudgetCategoryFactory.Serialize(budgetType);

            Assert.That(budgetTypeString, Is.EqualTo("Income:Salary"));
        }
예제 #2
0
        public void CanDeSerialize()
        {
            var budgetTypeString = "Income:Salary";
            var budgetType       = BudgetCategoryFactory.DeSerialize(budgetTypeString);

            Assert.That(budgetType, Is.EqualTo(BudgetType.Income_Salary));
        }
예제 #3
0
        public void CanDeserializeMainCategoryOnly()
        {
            var budgetTypeString = "Income";
            var budgetType       = BudgetCategoryFactory.DeSerialize(budgetTypeString);

            Assert.That(budgetType, Is.EqualTo(BudgetType.Income));
        }
예제 #4
0
        public void CanSerializeMainCategoryOnly()
        {
            var budgetType       = BudgetType.Income;
            var budgetTypeString = BudgetCategoryFactory.Serialize(budgetType);

            Assert.That(budgetTypeString, Is.EqualTo("Income"));
        }
예제 #5
0
        public virtual string Serialize()
        {
            var categoryString = BudgetCategoryFactory.Serialize(Category.BudgetType);
            var amountString   = Amount.ToString();

            return($"{categoryString},{amountString},{Label}");
        }
예제 #6
0
 public BudgetEntry(double amount, string label, BudgetType budgetType)
 {
     Amount        = amount;
     this.Label    = label;
     BudgetType    = budgetType;
     this.Category = BudgetCategoryFactory.GetBudgetCategory(budgetType);
 }
예제 #7
0
 static void GetCommonParameters(ref string[] components, out double amount, out string label, out BudgetType budgetType)
 {
     budgetType = BudgetCategoryFactory.DeSerialize(components[0]);
     amount     = double.Parse(components[1]);
     label      = components[2];
     components = components.Skip(3).ToArray();
 }
예제 #8
0
        private static void AddExpenses(Report report)
        {
            Console.WriteLine("When prompted, enter aggregated expenses...");
            var expenseCategories = BudgetCategoryFactory.GetExpenseCategories();

            foreach (var category in expenseCategories)
            {
                var amount     = GetPromptedAmount(category);
                var budgetType = BudgetCategoryFactory.GetBudgetType(category, "");
                report.AddExpenditure(budgetType, amount);
            }
        }
예제 #9
0
        private static void AddIncome(Report report)
        {
            Console.WriteLine("When prompted, enter income...");
            var incomeCategories = BudgetCategoryFactory.GetIncomeCategories();

            foreach (var category in incomeCategories)
            {
                var prompt     = string.IsNullOrWhiteSpace(category) ? "Unspecified Income" : category;
                var amount     = GetPromptedAmount(prompt);
                var budgetType = BudgetCategoryFactory.GetBudgetType("Income", category);
                report.AddExpenditure(budgetType, amount);
            }
        }
예제 #10
0
        public void IncomeCategoriesContainSubCategoriesFromSpecialIncomeMainCategory()
        {
            int numCategories = 0;

            foreach (BudgetType budgetType in Enum.GetValues(typeof(BudgetType)))
            {
                var components = budgetType.ToString().Split('_');
                if (components[0] == "Income")
                {
                    numCategories += 1;
                }
            }
            var mainCategories = BudgetCategoryFactory.GetIncomeCategories();

            Assert.That(mainCategories.Count, Is.EqualTo(numCategories));
        }
예제 #11
0
        public void ExpenseCategoriesContainParentCategories()
        {
            int numParents = 0;

            foreach (BudgetType budgetType in Enum.GetValues(typeof(BudgetType)))
            {
                var components = budgetType.ToString().Split('_');
                if (components.Length == 1 && components[0] != "Income")
                {
                    numParents += 1;
                }
            }
            var mainCategories = BudgetCategoryFactory.GetExpenseCategories();

            Assert.That(mainCategories.Count, Is.EqualTo(numParents));
        }
예제 #12
0
        public void GetBudgetTypeHandlesEmptySubCategories()
        {
            var budgetType = BudgetCategoryFactory.GetBudgetType("Income", "");

            Assert.That(budgetType, Is.EqualTo(BudgetType.Income));
        }
예제 #13
0
        public void CanGetBudgetTypeForValidCategories()
        {
            var budgetType = BudgetCategoryFactory.GetBudgetType("Income", "Misc");

            Assert.That(budgetType, Is.EqualTo(BudgetType.Income_Misc));
        }