public void Can_Sum_Incomes_Whole_Month()
        {
            var svc = new SummaryCalculationService();

            var incomes = new List<Income>();
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.01m, Date = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 01) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.02m, Date = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 05) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.03m, Date = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 10) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.04m, Date = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 15) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.05m, Date = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 25) });

            decimal incomesForTheMonth = 0;

            SystemTime.Now = () => new DateTime(2012, 12, 15);
            incomesForTheMonth = svc.CalculateBalanceForCurrentMonth(incomes);
            Assert.IsTrue(incomesForTheMonth == 50.15m );

            SystemTime.Now = () => new DateTime(2012, 11, 15);
            incomesForTheMonth = svc.CalculateBalanceForCurrentMonth(incomes);
            Assert.IsTrue(incomesForTheMonth == 0m);

            SystemTime.Now = () => new DateTime(2013, 01, 15);
            incomesForTheMonth = svc.CalculateBalanceForCurrentMonth(incomes);
            Assert.IsTrue(incomesForTheMonth == 0m);
        }
        public void Execute(CommandArgs args)
        {
            var sidePanelArg = args as SidePanelCommandArgs;
            if (sidePanelArg == null)
            {
                return;
            }
            if (sidePanelArg.WpfControl != null) _host.CurrentControl = sidePanelArg.WpfControl;
            if (sidePanelArg.Model != null) _host.Model = sidePanelArg.Model;

            _host.Refresh();
            _host.Show();

            //todo: only for tests
            var svc = new SummaryCalculationService();
            var currentMonthBalance = svc.CalculateBalanceForCurrentMonth(sidePanelArg.Transactions);
            var incomesUpToDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(sidePanelArg.Transactions, SystemTime.Now());
            var expensesUpToDate = svc.CalculateExpensesForCurrentMonthUpToGivenDate(sidePanelArg.Transactions, SystemTime.Now());
            var accountSummary = svc.CalculateAccountSummary(sidePanelArg.Accounts,
                                                             sidePanelArg.Transactions);

            Singleton<MainStatusAppService>.Instance.EndOfMonthBalance = currentMonthBalance;
            Singleton<MainStatusAppService>.Instance.IncomesUpToDate = incomesUpToDate;
            Singleton<MainStatusAppService>.Instance.ExpensesUpToDate = expensesUpToDate;
            Singleton<MainStatusAppService>.Instance.AccountSummary = accountSummary;
        }
        public void Can_Sum_Incomes_Up_To_Given_Date_In_Current_Month()
        {
            var svc = new SummaryCalculationService();
            SystemTime.Now = () => new DateTime(2012,12,15);

            var incomes = new List<Income>();
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.01m, Date = new DateTime(2012, 12, 02) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.02m, Date = new DateTime(2012, 12, 05) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.03m, Date = new DateTime(2012, 12, 10) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.04m, Date = new DateTime(2012, 12, 15) });
            incomes.Add(new Income { AccountId = 1, ActualValue = 10.05m, Date = new DateTime(2012, 12, 25) });

            decimal incomesForGivenDate = 0;

            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 11, 01));
            Assert.IsTrue(incomesForGivenDate == 0m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 01));
            Assert.IsTrue(incomesForGivenDate == 0m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 02));
            Assert.IsTrue(incomesForGivenDate == 10.01m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 03));
            Assert.IsTrue(incomesForGivenDate == 10.01m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 05));
            Assert.IsTrue(incomesForGivenDate == 20.03m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 06));
            Assert.IsTrue(incomesForGivenDate == 20.03m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 10));
            Assert.IsTrue(incomesForGivenDate == 30.06m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 11));
            Assert.IsTrue(incomesForGivenDate == 30.06m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 15));
            Assert.IsTrue(incomesForGivenDate == 40.10m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 16));
            Assert.IsTrue(incomesForGivenDate == 40.10m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 25));
            Assert.IsTrue(incomesForGivenDate == 50.15m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2012, 12, 30));
            Assert.IsTrue(incomesForGivenDate == 50.15m);
            incomesForGivenDate = svc.CalculateIncomesForCurrentMonthUpToGivenDate(incomes, new DateTime(2013, 01, 01));
            Assert.IsTrue(incomesForGivenDate == 0m);
        }