public void can_use_national_holidays_in_calulations()
        {
            DateTime nationalDay = new DateTime(2011, 6, 10);

            Assert.IsFalse(nationalDay.IsWorkingDay(pt_ci));
            Assert.IsTrue(nationalDay.IsHoliday(pt_ci));
        }
        public void can_use_christian_holidays_in_calulations()
        {
            DateTime corpus = new DateTime(2010, 12, 8);

            Assert.IsFalse(corpus.IsWorkingDay(pt_ci));
            Assert.IsTrue(corpus.IsHoliday(pt_ci));
        }
 public void assert_holidays_on_weekend_observed_on_monday()
 {
     var dateTimeCulture = new WorkingDayCultureInfo("fr-CA");
     // 01-07-2012 Canada Day on a Sunday
     var mondayAfterCanadaDay = new DateTime(2012, 07, 02);
     Assert.AreEqual(DayOfWeek.Monday, mondayAfterCanadaDay.DayOfWeek);
     Assert.IsFalse(mondayAfterCanadaDay.IsWorkingDay(dateTimeCulture));
 }
        public void check_working_day()
        {
            var ptWorkingDayCultureInfo = new DateTimeCultureInfo("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 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 can_provide_custom_locator_dayOfWeek_strategy()
        {
            var mockDayOfWeekStartegy = Substitute.For<IWorkingDayOfWeekStrategy>();
            mockDayOfWeekStartegy.IsWorkingDay(Arg.Any<DayOfWeek>()).Returns(false);

            WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo()
            {
                LocateWorkingDayOfWeekStrategy = (n) => { return mockDayOfWeekStartegy; }
            };

            DateTime aThursday = new DateTime(2011, 5, 12);
            Assert.IsFalse(aThursday.IsWorkingDay(workingdayCultureInfo));
            Assert.IsFalse(aThursday.IsHoliday(workingdayCultureInfo));
            mockDayOfWeekStartegy.Received().IsWorkingDay(aThursday.DayOfWeek);
        }
        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 can_provide_custom_locator_holiday_dayOfWeek_strategy()
        {
            var mockHolidayStrategy = Substitute.For<IHolidayStrategy>();
            mockHolidayStrategy.IsHoliDay(Arg.Any<DateTime>()).Returns(true);
            var mockDayOfWeekStartegy = Substitute.For<IWorkingDayOfWeekStrategy>();
            mockDayOfWeekStartegy.IsWorkingDay(Arg.Any<DayOfWeek>()).Returns(true);

            WorkingDayCultureInfo workingdayCultureInfo = new WorkingDayCultureInfo()
            {
                LocateHolidayStrategy = (n) => { return mockHolidayStrategy; },
                LocateWorkingDayOfWeekStrategy = (n) => { return mockDayOfWeekStartegy; }
            };

            DateTime marchFirst = new DateTime(1991, 3, 1);
            Assert.IsTrue(marchFirst.IsHoliday(workingdayCultureInfo));
            Assert.IsFalse(marchFirst.IsWorkingDay(workingdayCultureInfo));
            mockHolidayStrategy.Received().IsHoliDay(marchFirst);
            mockDayOfWeekStartegy.Received().IsWorkingDay(marchFirst.DayOfWeek);
        }
Example #9
0
        private static IEnumerable<ActivityDay> CreateMonthDays(int consiltantId, int year, int month)
        {
            var nbOfDays = DateTime.DaysInMonth(year, month);
            var activityDays = new List<ActivityDay>();

            for (var i = 1; i <= nbOfDays; i++)
            {
                var date = new DateTime(year, month, i);
                var day = new ActivityDay
                              {
                                  Date = date,
                                  ConsultantId = consiltantId,
                                  IsWorkingDay = date.IsWorkingDay(),
                                  MorningActivity = new Activity
                                  {
                                      ActivityType = ActivityType.Vide,
                                      ConsultantId = consiltantId,
                                      Date = date
                                  },
                                  AfternoonActivity = new Activity
                                  {
                                      ActivityType = ActivityType.Vide,
                                      ConsultantId = consiltantId,
                                      Date = date
                                  }
                              };

                activityDays.Add(day);
            }

            return activityDays;
        }
		private IEnumerable<DayViewModel> BuildDaysForMonthViewModel(int year, int month) {
			var daysInMonth = GregorianCalendar.GetDaysInMonth(year, month);
			for (int i = 1; i <= daysInMonth; i++) {
				var day = new DateTime(year, month, i);
				yield return new DayViewModel {
					DayText = i.ToString(),
					IsWorkingDay = day.IsWorkingDay(workingdayCultureInfo),
					IsHoliday = day.IsHoliday(workingdayCultureInfo)
				};
			}
		}
        public static DateTime FirstWorkingDayOfThisMonth(this DateTime value)
        {
            var res = new DateTime(value.Year, value.Month, 1);
            while (!res.IsWorkingDay())
                res = res.AddDays(1);

            return res;
        }
        public void IsWorkingDay_WithWorkingDayDate_ExpectTrue(
            int year,
            int month,
            int day)
        {
            // Arrange
            DateTimeExtensions.MinValid = new DateTime(year, 1, 1);
            DateTimeExtensions.MaxValid = new DateTime(year, 12, 31);

            AddHolidays(DateTimeExtensions.Holidays);

            var classUnderTest = new DateTime(year, month, day, 23, 53, 59);

            // Act
            var actual = classUnderTest.IsWorkingDay();

            // Assert
            Assert.AreEqual(true, actual);
        }