public void EndingCurrentYear_EndDateIsCorrect(Ending ending, string currentDateString, string dateTimeString)
        {
            var dnp = new Mock <IDotNetProvider>();

            dnp.Setup(_ => _.DateTimeNow).Returns(DateTime.Parse(currentDateString));

            Accrual accrual = CreateAccrualInstance(ending);

            DateTime end = accrual.GetEndDate(dnp.Object);

            end.ShouldBe(DateTime.Parse(dateTimeString));
        }
Ejemplo n.º 2
0
        private List <AccrualRow> CreateAccrualTable(Accrual config)
        {
            DateTime previous = config.StartingDate;
            DateTime current  = config.StartingDate;
            DateTime end      = config.GetEndDate(_dotNetProvider);

            var rows = new List <AccrualRow>
            {
                new AccrualRow(0, null, 0, config.StartingHours, null)
            };

            double accrual = config.StartingHours;

            int counter = 1;

            while (current <= end)
            {
                DateTime c = current, p = previous;
                var      actions = config.Actions
                                   .Where(a => a.AccrualAction != AccrualAction.Created)
                                   .Where(a => a.ActionDate >= p && a.ActionDate < c);
                double sum = actions.Sum(x => x.Amount).GetValueOrDefault();

                accrual += config.AccrualRate + sum;

                rows.Add(new AccrualRow(counter++, current, sum, accrual, actions));

                previous = current;

                if (config.AccrualFrequency == AccrualFrequency.Biweekly)
                {
                    current = current.AddDays(14);
                }
                else
                {
                    int day = current.Day;
                    if (day >= config.DayOfPayB)
                    {
                        current = current.AddMonths(1);
                        current = new DateTime(current.Year, current.Month, config.DayOfPayA.Value);
                    }
                    else
                    {
                        current = new DateTime(current.Year, current.Month, config.DayOfPayB.Value);
                    }
                }
            }

            return(rows);
        }