示例#1
0
        public static BudgetEntry CreateBudgetEntry(params string[] components)
        {
            BudgetEntry result = null;

            double     amount;
            string     label;
            BudgetType budgetType;
            int        month;
            string     dayStart;
            int        weekPeriod;
            int        weekMax;

            string type;

            GetNextValueAndAdvance(ref components, out type);
            GetCommonParameters(ref components, out amount, out label, out budgetType);
            switch (type)
            {
            case "Annual":
                GetNextValueAndAdvance(ref components, out month);
                result = new BudgetEntryAnnual(amount, month, label, budgetType);
                break;

            case "BiAnnual":
                GetNextValueAndAdvance(ref components, out month);
                result = new BudgetEntryBiAnnual(amount, month, label, budgetType);
                break;

            case "Monthly":
                result = new BudgetEntryMonthly(amount, label, budgetType);
                break;

            case "BiMonthly":
                GetNextValueAndAdvance(ref components, out month);
                result = new BudgetEntryBiMonthly(amount, month, label, budgetType);
                break;

            case "Weekly":
                GetNextValueAndAdvance(ref components, out dayStart);
                GetNextValueAndAdvance(ref components, out weekPeriod);
                GetNextValueAndAdvance(ref components, out weekMax);
                result = new BudgetEntryWeekly(amount, label, budgetType, weekPeriod, dayStart, weekMax);
                break;

            case "Daily":
                GetNextValueAndAdvance(ref components, out dayStart);
                result = new BudgetEntryDaily(amount, label, budgetType, dayStart);
                break;

            default:
                throw new ArgumentException($"Invalid Budget Entry Type {type}");
            }
            return(result);
        }
示例#2
0
        public void CanSupportBiAnnualBudgetEntries()
        {
            var entry1 = new BudgetEntryBiAnnual(300, 5, "Progressive BMW", BudgetType.Auto_Insurance);
            var entry2 = new BudgetEntryBiAnnual(100, 12, "Vespa", BudgetType.Auto_Insurance);

            _budget.AddEntry(entry1);
            Assert.That(_budget.TotalExpenses, Is.EqualTo(600.00));
            Assert.That(_budget.MonthlyExpenses(5), Is.EqualTo(300.00));
            Assert.That(_budget.MonthlyExpenses(11), Is.EqualTo(300.0));
            Assert.That(_budget.MonthlyExpenses(12), Is.EqualTo(0.0));
            _budget.AddEntry(entry2);
            Assert.That(_budget.MonthlyExpenses(6), Is.EqualTo(100.0));
            Assert.That(_budget.MonthlyExpenses(12), Is.EqualTo(100.0));
            Assert.That(_budget.MonthlyExpenses(1), Is.EqualTo(0.0));
        }