Exemplo n.º 1
0
        public void TestGetHoliday()
        {
            // arrange
            List <TimeRecord> period    = new List <TimeRecord>();
            DateTime          firstDate = new DateTime(2016, 12, 14);

            for (int i = 0; i < 14; i++)
            {
                period.Add(new TimeRecord(firstDate.AddDays(i)));
            }

            // Act
            List <Holiday> holidays = PayPeriod.GetHoliday();

            foreach (TimeRecord record in period)
            {
                Trace.Write("Record: ");
                Trace.Write(record.RecordDate.Date);
                Trace.Write("\n");
                foreach (var holiday in holidays)
                {
                    Trace.Write("\tHoliday: ");
                    Trace.Write(holiday.HolidayDate.Date);
                    Trace.Write("\n");
                    if (record.RecordDate.Date == holiday.HolidayDate.Date ||
                        record.RecordDate.DayOfWeek == DayOfWeek.Sunday ||
                        record.RecordDate.DayOfWeek == DayOfWeek.Saturday)
                    {
                        record.IsHoliday = true;
                        break;
                    }
                }
                Trace.Write("Result: ");
                Trace.Write(record.IsHoliday);
                Trace.Write("\n");
            }

            // Assert
            // 14 Dec is NOT a holiday
            Assert.AreEqual(false, period[0].IsHoliday);

            // Saturday is a holiday
            Assert.AreEqual(true, period[3].IsHoliday);

            // Sunday is a holiday
            Assert.AreEqual(true, period[4].IsHoliday);

            // 25 Dec Chrismas Day is a holiday in NAT
            Assert.AreEqual(true, period[11].IsHoliday);

            // 27 Dec is a substitue Chrismas Day holiday in NSW
            Assert.AreEqual(true, period[13].IsHoliday);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Download and update <see cref="Holiday"/> from government website.
        /// </summary>
        /// <returns>Refreshed holidays view.</returns>
        //[ValidateAntiForgeryToken]
        public ActionResult UpdateHolidays()
        {
            List <Holiday> holidayList = adminDb.Holidays.ToList();

            if (holidayList.Count != 0)
            {
                foreach (Holiday item in holidayList)
                {
                    adminDb.Holidays.Remove(item);
                }
                adminDb.SaveChanges();
            }

            holidayList = PayPeriod.GetHoliday();
            foreach (Holiday item in holidayList)
            {
                adminDb.Holidays.Add(item);
            }
            adminDb.SaveChanges();

            return(RedirectToAction("Holidays"));
        }