Exemple #1
0
        public void AfterUpdateLastModifiedIsUpdated()
        {
            BudgetModel subject = BudgetModelTestData.CreateTestData1();

            DateTime lastUpdated = subject.LastModified;

            Thread.Sleep(10);
            subject.Update(subject.Incomes, subject.Expenses);

            Assert.AreNotEqual(lastUpdated, subject.LastModified);
        }
        public void UpdateIncomesAndExpenses(
            [NotNull] BudgetModel model,
            IEnumerable <Income> allIncomes,
            IEnumerable <Expense> allExpenses)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            // Copy view model bound data back into model.
            model.Update(allIncomes, allExpenses);
        }
Exemple #3
0
        /// <summary>
        ///     A budget model that is effective from 01/1/13.
        ///     Includes InsHome, and PhoneInternet, CarMtc, HairCut, Power
        ///     Designed for use with LedgerBookTestData5 and StatementModelTestData5
        /// </summary>
        public static BudgetModel CreateTestData5()
        {
            var budget = new BudgetModel
            {
                EffectiveFrom = new DateTime(2013, 01, 01),
                Name          = TestDataConstants.Budget5Name
            };

            var expenses = new List <Expense>(
                new[]
            {
                new Expense
                {
                    Amount = 300M,
                    Bucket = new SavedUpForExpenseBucket(TestDataConstants.InsuranceHomeBucketCode, "Home Insurance")
                },
                new Expense
                {
                    Amount = 120M,
                    Bucket = new SavedUpForExpenseBucket(TestDataConstants.PhoneBucketCode, "Phone/Internet")
                },
                new Expense
                {
                    Amount = 100M,
                    Bucket = new SavedUpForExpenseBucket(TestDataConstants.CarMtcBucketCode, "Car maintenance")
                },
                new Expense
                {
                    Amount = 65M,
                    Bucket = new SpentMonthlyExpenseBucket(TestDataConstants.HairBucketCode, "Hair cuts")
                },
                new Expense
                {
                    Amount = 185M,
                    Bucket = new SpentMonthlyExpenseBucket(TestDataConstants.PowerBucketCode, "Power")
                }
            });

            var incomes = new List <Income>(
                new[]
            {
                new Income
                {
                    Amount = 2600M,
                    Bucket = new IncomeBudgetBucket(TestDataConstants.IncomeBucketCode, "Pay")
                }
            });

            budget.Update(incomes, expenses);
            return(budget);
        }
Exemple #4
0
        public void SurplusCannotBeUsedInTheExpenseList()
        {
            BudgetModel subject = BudgetModelTestData.CreateTestData1();

            List <Expense> myExpenses = subject.Expenses.ToList();

            myExpenses.Add(new Expense {
                Amount = 445M, Bucket = new SurplusBucket()
            });
            List <Income> myIncomes = subject.Incomes.ToList();

            subject.Update(myIncomes, myExpenses);

            Assert.Fail();
        }
Exemple #5
0
        public void AfterUpdateIncomesAreReplaced()
        {
            BudgetModel subject = BudgetModelTestData.CreateTestData1();

            var incomes = new List <Income>
            {
                new Income {
                    Amount = 9999, Bucket = new IncomeBudgetBucket("Foo", "Bar")
                },
                new Income {
                    Amount = 4444, Bucket = new IncomeBudgetBucket("Horse", "Shit")
                }
            };

            subject.Update(incomes, subject.Expenses);

            Assert.AreEqual(9999M + 4444M, subject.Incomes.Sum(i => i.Amount));
        }
Exemple #6
0
        public void AfterUpdateExpensesAreStillInDescendingOrder()
        {
            BudgetModel subject = BudgetModelTestData.CreateTestData1();

            var expenses = new List <Expense>
            {
                new Expense {
                    Amount = 4444, Bucket = new SpentMonthlyExpenseBucket("Horse", "Shit")
                },
                new Expense {
                    Amount = 9999, Bucket = new SavedUpForExpenseBucket("Foo", "Bar")
                }
            };

            subject.Update(subject.Incomes, expenses);

            EnsureDescendingOrder(subject.Expenses);
        }
Exemple #7
0
        public void AfterUpdateExpensesAreReplaced()
        {
            BudgetModel subject = BudgetModelTestData.CreateTestData1();

            var expenses = new List <Expense>
            {
                new Expense {
                    Amount = 4444, Bucket = new SpentMonthlyExpenseBucket("Horse", "Shit")
                },
                new Expense {
                    Amount = 9999, Bucket = new SavedUpForExpenseBucket("Foo", "Bar")
                }
            };

            subject.Update(subject.Incomes, expenses);

            Assert.AreEqual(4444M + 9999M, subject.Expenses.Sum(e => e.Amount));
        }
Exemple #8
0
        public void AfterUpdateIncomesAreStillInDescendingOrder()
        {
            BudgetModel subject = BudgetModelTestData.CreateTestData1();

            var incomes = new List <Income>
            {
                new Income {
                    Amount = 4444, Bucket = new IncomeBudgetBucket("Horse", "Shit")
                },
                new Income {
                    Amount = 9999, Bucket = new IncomeBudgetBucket("Foo", "Bar")
                }
            };

            subject.Update(incomes, subject.Expenses);

            EnsureDescendingOrder(subject.Incomes);
        }
        public BudgetModel CloneBudgetModel(BudgetModel sourceBudget, DateTime newBudgetEffectiveFrom)
        {
            if (sourceBudget == null)
            {
                throw new ArgumentNullException(nameof(sourceBudget));
            }

            if (newBudgetEffectiveFrom <= sourceBudget.EffectiveFrom)
            {
                throw new ArgumentException("The effective date of the new budget must be later than the other budget.", nameof(newBudgetEffectiveFrom));
            }

            if (newBudgetEffectiveFrom <= DateTime.Today)
            {
                throw new ArgumentException("The effective date of the new budget must be a future date.", nameof(newBudgetEffectiveFrom));
            }

            var validationMessages = new StringBuilder();

            if (!sourceBudget.Validate(validationMessages))
            {
                throw new ValidationWarningException(string.Format(CultureInfo.CurrentCulture, "The source budget is currently in an invalid state, unable to clone it at this time.\n{0}", validationMessages));
            }

            var newBudget = new BudgetModel
            {
                EffectiveFrom = newBudgetEffectiveFrom,
                Name          = string.Format(CultureInfo.CurrentCulture, "Copy of {0}", sourceBudget.Name)
            };

            newBudget.Update(CloneBudgetIncomes(sourceBudget), CloneBudgetExpenses(sourceBudget));

            if (!newBudget.Validate(validationMessages))
            {
                throw new InvalidOperationException("New cloned budget is invalid but the source budget is ok. Code Error.\n" + validationMessages);
            }

            Budgets.Add(newBudget);
            this.budgetRepository.SaveAsync();
            UpdateServiceMonitor();
            return(newBudget);
        }