Exemplo n.º 1
0
        public void Populate_PayrollDayOfWeekOvertime_Successful()
        {
            var db          = new SqlContext();
            var currentUser = db.Users.Find(1);

            var service = new PunchService();
            var inAt    = new DateTime(2020, 1, 1);
            var outAt   = new DateTime(2020, 1, 31);

            var originalPunches = GetPunches()
                                  .OrderBy(p => p.UserId)
                                  .ThenBy(p => p.InAt)
                                  .ToList();

            // Splitting happens automatically during populate below

            var populateOptions = new PopulateRateOptions();

            populateOptions.InAt    = new DateTime(2020, 1, 1);
            populateOptions.OutAt   = new DateTime(2020, 1, 31);
            populateOptions.Options = new PopulateRateOption[]
            {
                // This option should populate anything
                // on Saturday with the overtime rate
                new PopulateRateOption()
                {
                    Type                   = "dayofweek",
                    DayOfWeek              = "Saturday",
                    BasePayrollRateId      = 1,
                    AlternatePayrollRateId = 2,
                    Order                  = 0
                }
            };

            var populatedPunches = service.Populate(populateOptions, originalPunches, currentUser);

            // Assert the number of punches after automatic split
            Assert.AreEqual(21, populatedPunches.Count);

            foreach (var punch in populatedPunches)
            {
                if (punch.InAt.DayOfWeek == DayOfWeek.Saturday)
                {
                    Assert.IsTrue(punch.PayrollRateId == 2);
                }
                else
                {
                    Assert.IsTrue(punch.PayrollRateId == 1);
                }
            }
        }
Exemplo n.º 2
0
        public void Populate_PayrollFourHoursPerDayOvertime_Successful()
        {
            var db          = new SqlContext();
            var currentUser = db.Users.Find(1);

            var service = new PunchService();
            var inAt    = new DateTime(2020, 1, 1);
            var outAt   = new DateTime(2020, 1, 31);

            var originalPunches = GetPunches()
                                  .OrderBy(p => p.UserId)
                                  .ThenBy(p => p.InAt)
                                  .ToList();

            // Splitting happens automatically during populate below

            var populateOptions = new PopulateRateOptions();

            populateOptions.InAt    = new DateTime(2020, 1, 1);
            populateOptions.OutAt   = new DateTime(2020, 1, 31);
            populateOptions.Options = new PopulateRateOption[]
            {
                // This option should populate anything
                // after 4 hours per day with the overtime rate
                new PopulateRateOption()
                {
                    Type                   = "count",
                    CountScope             = "day",
                    CountMinute            = 240,
                    BasePayrollRateId      = 1,
                    AlternatePayrollRateId = 2,
                    Order                  = 0
                }
            };

            var populatedPunches = service.Populate(populateOptions, originalPunches, currentUser);

            // Assert the number of punches after automatic split
            Assert.AreEqual(38, populatedPunches.Count);

            var userIds = populatedPunches.GroupBy(p => p.UserId).Select(g => g.Key);

            foreach (var userId in userIds)
            {
                // Assert that punches over 4 hours per day (240 minutes) are overtime
                var filtered = populatedPunches.Where(p => p.UserId == userId);
                var dates    = filtered
                               .GroupBy(p => p.InAt.Date)
                               .Select(g => new {
                    Date = g.Key
                })
                               .ToList();

                foreach (var date in dates)
                {
                    var punchesForDay = filtered
                                        .Where(p => p.InAt.Date == date.Date)
                                        .ToList();
                    var count = 0;
                    foreach (var punch in punchesForDay)
                    {
                        count += punch.Minutes;
                        if (count <= 240)
                        {
                            Assert.IsTrue(punch.PayrollRateId == 1);
                        }
                        else
                        {
                            Assert.IsTrue(punch.PayrollRateId == 2);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Populate_PayrollBeforeSevenAmAfterFivePmAsOvertime_Successful()
        {
            var db          = new SqlContext();
            var currentUser = db.Users.Find(1);

            var service = new PunchService();
            var inAt    = new DateTime(2020, 1, 1);
            var outAt   = new DateTime(2020, 1, 31);

            var originalPunches = GetPunches()
                                  .OrderBy(p => p.UserId)
                                  .ThenBy(p => p.InAt)
                                  .ToList();

            // Splitting happens automatically during populate below

            var populateOptions = new PopulateRateOptions();

            populateOptions.InAt    = new DateTime(2020, 1, 1);
            populateOptions.OutAt   = new DateTime(2020, 1, 31);
            populateOptions.Options = new PopulateRateOption[]
            {
                // This option should populate anything
                // from midnight through 7am with the overtime rate
                new PopulateRateOption()
                {
                    Type                   = "range",
                    RangeDirection         = "before",
                    RangeMinutes           = 420,
                    BasePayrollRateId      = 1,
                    AlternatePayrollRateId = 2,
                    Order                  = 0
                },

                // This option should populate anything
                // from 5pm through midnight with overtime rate
                new PopulateRateOption()
                {
                    Type                   = "range",
                    RangeDirection         = "after",
                    RangeMinutes           = 1020,
                    BasePayrollRateId      = 1,
                    AlternatePayrollRateId = 2,
                    Order                  = 1
                }
            };

            var populatedPunches = service.Populate(populateOptions, originalPunches, currentUser);

            // Assert the number of punches after automatic split
            Assert.AreEqual(34, populatedPunches.Count);

            foreach (var punch in populatedPunches.Where(p => p.UserId == 3))
            {
                var midnight     = new DateTime(punch.InAt.Year, punch.InAt.Month, punch.InAt.Day, 0, 0, 0, 0);
                var spanInAt     = punch.InAt.Subtract(midnight);
                var minuteOfInAt = spanInAt.TotalMinutes;

                switch (punch.PayrollRateId)
                {
                case 1:
                    // Should be regular
                    Assert.IsTrue(minuteOfInAt >= 420 || minuteOfInAt <= 1020);
                    break;

                case 2:
                    // Should be overtime
                    Assert.IsTrue(minuteOfInAt <= 420 || minuteOfInAt >= 1020);
                    break;
                }
            }
        }