public void can_locate_by_name()
 {
     string name = "pt-PT";
     WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo(name);
     Assert.IsTrue(name == workingdayCultureInfo.Name);
     Assert.IsInstanceOf<PT_PTHolidayStrategy>(workingdayCultureInfo.LocateHolidayStrategy(name));
 }
 public void can_locate_by_culture_info()
 {
     string name = "pt-PT";
     System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(name);
     WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo();
     Assert.IsTrue(name == workingdayCultureInfo.Name);
     Assert.IsInstanceOf<PT_PTHolidayStrategy>(workingdayCultureInfo.LocateHolidayStrategy(name));
 }
 public void can_locate_default_strategies()
 {
     string name = "foo";
     WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo(name);
     Assert.IsTrue(name == workingdayCultureInfo.Name);
     Assert.IsInstanceOf<DefaultHolidayStrategy>(workingdayCultureInfo.LocateHolidayStrategy(name));
     Assert.IsInstanceOf<DefaultWorkingDayOfWeekStrategy>(workingdayCultureInfo.LocateWorkingDayOfWeekStrategy(name));
 }
        public void check_working_day()
        {
            var ptWorkingDayCultureInfo = new WorkingDayCultureInfo("pt-PT");
            var carnationRevolution = new DateTime(2011, 4, 25);
            var nextDay = carnationRevolution.AddDays(1);

            Assert.IsTrue(carnationRevolution.IsWorkingDay() == false);
            Assert.IsTrue(carnationRevolution.DayOfWeek == DayOfWeek.Monday);

            Assert.IsTrue(nextDay.IsWorkingDay() == true);
            Assert.IsTrue(nextDay.DayOfWeek == DayOfWeek.Tuesday);
        }
        public void get_this_year_holidays_in_portugal()
        {
            var portugalWorkingDayCultureInfo = new WorkingDayCultureInfo("pt-PT");
            var today = DateTime.Today;
            var holidays = today.AllYearHolidays();

            Assert.IsTrue(holidays.Count == 13);

            foreach (DateTime holidayDate in holidays.Keys) {
                var holiday = holidays[holidayDate];
                Assert.IsTrue(holidayDate.IsWorkingDay(portugalWorkingDayCultureInfo) == false, "holiday {0} shouln't be working day in Portugal", holiday.Name);
            }
        }
        public void can_provide_custom_locator_dayOfWeek_strategy()
        {
            dynamicMockDayOfWeek.ExpectAndReturn("IsWorkingDay", false, new object[] { DayOfWeek.Thursday });

            WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo() {
                LocateWorkingDayOfWeekStrategy = (n) => {
                    return (IWorkingDayOfWeekStrategy)dynamicMockDayOfWeek.MockInstance;
                }
            };

            DateTime aThursday = new DateTime(2011, 5, 12);
            Assert.IsFalse(aThursday.IsWorkingDay(workingdayCultureInfo));
        }
        public void holidays()
        {
            var ptWorkingDayCultureInfo = new WorkingDayCultureInfo("pt-PT");
            var enWorkingDayCultureInfo = new WorkingDayCultureInfo("default");

            var thursday = new DateTime(2011, 4, 21); // A thursday
            var thursday_plus_two_working_days_pt = thursday.AddWorkingDays(2, ptWorkingDayCultureInfo); // friday + 2 working days on PT
            var thursday_plus_two_working_days_en = thursday.AddWorkingDays(2, enWorkingDayCultureInfo); // friday + 2 working days on Default

            //Default doesn't have supported holidays
            Assert.IsTrue(thursday_plus_two_working_days_en == thursday.AddDays(4));
            Assert.IsTrue(thursday_plus_two_working_days_en.DayOfWeek == DayOfWeek.Monday);

            //Portuguese Holidays are supported
            Assert.IsTrue(thursday_plus_two_working_days_pt == thursday.AddDays(6)); // + Good Friday (22-4-2011) + Carnation Revolution (25-4-2011)
            Assert.IsTrue(thursday_plus_two_working_days_pt.DayOfWeek == DayOfWeek.Wednesday);
        }
        public void can_provide_custom_locator_holiday_dayOfWeek_strategy()
        {
            dynamicMockHoliday.ExpectAndReturn("IsHoliDay", true, new object[] { new DateTime(1991, 3, 1) });
            dynamicMockDayOfWeek.ExpectAndReturn("IsWorkingDay", true, new object[] { DayOfWeek.Friday });
            dynamicMockDayOfWeek.ExpectAndReturn("IsWorkingDay", true, new object[] { DayOfWeek.Friday });

            WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo() {
                LocateHolidayStrategy = (n) => {
                    return (IHolidayStrategy)dynamicMockHoliday.MockInstance;
                },
                LocateWorkingDayOfWeekStrategy = (n) => {
                    return (IWorkingDayOfWeekStrategy)dynamicMockDayOfWeek.MockInstance;
                }
            };

            DateTime marchFirst = new DateTime(1991, 3, 1);
            Assert.IsFalse(marchFirst.IsWorkingDay(workingdayCultureInfo));
        }
        public void recomended_calculation()
        {
            var workingDayCultureInfo = new WorkingDayCultureInfo("pt-PT");
            var friday = new DateTime(2011, 5, 13); // A friday
            var friday_plus_two_working_days = friday.AddWorkingDays(2, workingDayCultureInfo); // friday + 2 working days

            Assert.IsTrue(friday_plus_two_working_days == friday.AddDays(4));
            Assert.IsTrue(friday_plus_two_working_days.DayOfWeek == DayOfWeek.Tuesday);
        }
        public void provide_custom_strategies()
        {
            var customWorkingDayCultureInfo = new WorkingDayCultureInfo() {
                LocateHolidayStrategy = (name) => new CustomHolidayStrategy() ,
                LocateWorkingDayOfWeekStrategy = (name) => new CustomeWorkingDayOfWeekStrategy()
            };

            Assert.IsTrue(DateTime.Today.IsWorkingDay(customWorkingDayCultureInfo) == false);
            Assert.IsTrue(DateTime.Today.AddDays(1).IsWorkingDay(customWorkingDayCultureInfo) == true);
        }
 public static bool IsWorkingDay(this DateTime day)
 {
     var workingDayCultureInfo = new WorkingDayCultureInfo();
     return IsWorkingDay(day, workingDayCultureInfo);
 }
 public static IDictionary<DateTime, Holiday> AllYearHolidays(this DateTime day)
 {
     var workingDayCultureInfo = new WorkingDayCultureInfo();
     return AllYearHolidays(day, workingDayCultureInfo);
 }