public void Can_calculate_simple_cashflow_with_more_than_one_account()
        {
            #region Scenario

            var incomes = new List<Income>();
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1500.10m, Date = new DateTime(2012, 04, 01) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1500.14m, Date = new DateTime(2012, 04, 05) });
            incomes.Add(new Income { AccountId = 4, ExpectedValue = 1500.00m, ActualValue = 1430.00m, Date = new DateTime(2012, 04, 05) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1250.00m, Date = new DateTime(2012, 04, 07) });
            incomes.Add(new Income { AccountId = 4, ExpectedValue = 1500.00m, ActualValue = 1500.11m, Date = new DateTime(2012, 04, 02) });
            incomes.Add(new Income { AccountId = 3, ExpectedValue = 1500.00m, ActualValue = null, Date = new DateTime(2012, 04, 03) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = null, ActualValue = 1500.13m, Date = new DateTime(2012, 04, 04) });

            var expenses = new List<Expense>();
            expenses.Add(new Expense { AccountId = 3, ExpectedValue = 1450.00m, ActualValue = 1600.00m, Date = new DateTime(2012, 03, 31) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1700.21m, Date = new DateTime(2012, 04, 01) });
            expenses.Add(new Expense { AccountId = 3, ExpectedValue = 1300.00m, ActualValue = null, Date = new DateTime(2012, 04, 05) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = null, ActualValue = 1150.22m, Date = new DateTime(2012, 04, 06) });
            expenses.Add(new Expense { AccountId = 4, ExpectedValue = 1450.00m, ActualValue = 1130.21m, Date = new DateTime(2012, 04, 02) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1200.21m, Date = new DateTime(2012, 04, 03) });
            expenses.Add(new Expense { AccountId = 4, ExpectedValue = 1450.00m, ActualValue = 1300.81m, Date = new DateTime(2012, 04, 04) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1150.22m, Date = new DateTime(2012, 04, 05) });

            #endregion

            var service = new BalanceCalculationService();

            var cashflow = service.CalculateCashflow(new CalculationArgs(incomes, expenses)
            {
                StartingDate = new DateTime(2012, 03, 30),
                EndingDate = new DateTime(2012, 04, 08)
            });

               var balance1 = service.CalculateBalance(new CalculationArgs(incomes, expenses)
            {
                StartingDate = new DateTime(2012, 03, 30),
                EndingDate = new DateTime(2012, 04, 08)
            });

            Assert.IsTrue(balance1.ForAccountId(1) == 549.51m);
            Assert.IsTrue(balance1.ForAccountId(3) == -1400m);
            Assert.IsTrue(balance1.ForAccountId(4) == 499.09m);

            //cash flows per date and accountID = 1
            Assert.IsTrue(cashflow.At(new DateTime(2012, 03, 31), 1).Value == 0.0m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 01), 1).Value == -200.11m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 02), 1).Value == -200.11m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 03), 1).Value == -1400.32m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 04), 1).Value == 99.81m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 05), 1).Value == 449.73m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 06), 1).Value == -700.49m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 07), 1).Value == 549.51m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 08), 1).Value == 549.51m);

            //cash flows per date and accountID = 3
            Assert.IsTrue(cashflow.At(new DateTime(2012, 03, 31), 3).Value == -1600m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 01), 3).Value == -1600m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 02), 3).Value == -1600m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 03), 3).Value == -100.00m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 04), 3).Value == -100.00000000m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 05), 3).Value == -1400m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 06), 3).Value == -1400m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 07), 3).Value == -1400m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 08), 3).Value == -1400m);

            //cash flows per date and accountID = 4
            Assert.IsTrue(cashflow.At(new DateTime(2012, 03, 31), 4).Value == 00000m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 01), 4).Value == 0m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 02), 4).Value == 369.90m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 03), 4).Value == 369.9m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 04), 4).Value == -930.91m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 05), 4).Value == 499.09m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 06), 4).Value == 499.09m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 07), 4).Value == 499.09m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 08), 4).Value == 499.09m);

            //test with different intervals
            var cashflow2 = service.CalculateCashflow(new CalculationArgs(incomes, expenses)
            {
                StartingDate = new DateTime(2012, 04, 02),
                EndingDate = new DateTime(2012, 04, 05)
            });

            Assert.IsTrue(cashflow2.At(new DateTime(2012, 04, 01), 1).Value == 0);
            Assert.IsTrue(cashflow2.At(new DateTime(2012, 04, 02), 1).Value == 0);
            Assert.IsTrue(cashflow2.At(new DateTime(2012, 04, 03), 1).Value == -1200.21m);
            Assert.IsTrue(cashflow2.At(new DateTime(2012, 04, 04), 1).Value == 299.92m);
            Assert.IsTrue(cashflow2.At(new DateTime(2012, 04, 05), 1).Value == 649.84m);
            Assert.IsTrue(cashflow2.At(new DateTime(2012, 04, 06), 1).Value == 649.84m);
        }
        public void Can_calculate_simple_cashflow_for_one_account()
        {
            var incomes = new List<Income>();
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1500.10m, Date = new DateTime(2012, 04, 01) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1500.14m, Date = new DateTime(2012, 04, 05) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1430.00m, Date = new DateTime(2012, 04, 05) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1250.00m, Date = new DateTime(2012, 04, 07) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = 1500.11m, Date = new DateTime(2012, 04, 02) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = 1500.00m, ActualValue = null, Date = new DateTime(2012, 04, 03) });
            incomes.Add(new Income { AccountId = 1, ExpectedValue = null, ActualValue = 1500.13m, Date = new DateTime(2012, 04, 04) });

            var expenses = new List<Expense>();
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1600.00m, Date = new DateTime(2012, 03, 31) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1700.21m, Date = new DateTime(2012, 04, 01) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1300.00m, ActualValue = null,     Date = new DateTime(2012, 04, 05) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = null,     ActualValue = 1150.22m, Date = new DateTime(2012, 04, 06) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1130.21m, Date = new DateTime(2012, 04, 02) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1200.21m, Date = new DateTime(2012, 04, 03) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1300.81m, Date = new DateTime(2012, 04, 04) });
            expenses.Add(new Expense { AccountId = 1, ExpectedValue = 1450.00m, ActualValue = 1150.22m, Date = new DateTime(2012, 04, 05) });
            var service = new BalanceCalculationService();

            var cashflow = service.CalculateCashflow(new CalculationArgs(incomes, expenses)
            {
                StartingDate = new DateTime(2012, 03, 30),
                EndingDate = new DateTime(2012, 04, 08)
            });

            Assert.IsTrue(cashflow.At(new DateTime(2012,03,31),1).Value==-1600.0m);
            Assert.IsTrue(cashflow.At(new DateTime(2012,04,01),1).Value==-1800.11m);
            Assert.IsTrue(cashflow.At(new DateTime(2012,04,02),1).Value==-1430.21m);
            Assert.IsTrue(cashflow.At(new DateTime(2012,04,03),1).Value==-1130.42m);
            Assert.IsTrue(cashflow.At(new DateTime(2012,04,04),1).Value==-931.10m);
            Assert.IsTrue(cashflow.At(new DateTime(2012,04,05),1).Value==-451.18m);
            Assert.IsTrue(cashflow.At(new DateTime(2012,04,06),1).Value==-1601.40m);
            Assert.IsTrue(cashflow.At(new DateTime(2012,04,07),1).Value==-351.40m);

            var balance1 = service.CalculateBalance(new CalculationArgs(incomes, expenses)
            {
                StartingDate = new DateTime(2012, 03, 30),
                EndingDate = new DateTime(2012, 04, 08)
            });

            Assert.IsTrue(balance1.ForAccountId(1) == -351.40m);

            //test smaller period
            cashflow = service.CalculateCashflow(new CalculationArgs(incomes, expenses)
            {
                StartingDate = new DateTime(2012, 04, 02),
                EndingDate = new DateTime(2012, 04, 04)
            });

            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 02), 1).Value == 369.90m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 03), 1).Value == 669.69m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 04), 1).Value == 869.01m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 04, 05), 1).Value == 869.01m);
            Assert.IsTrue(cashflow.At(new DateTime(2012, 05, 05), 1).Value == 869.01m);

            var balance2 = service.CalculateBalance(new CalculationArgs(incomes, expenses)
            {
                StartingDate = new DateTime(2012, 04, 02),
                EndingDate = new DateTime(2012, 04, 04)
            });

            Assert.IsTrue(balance2.ForAccountId(1) == 869.01m);
        }