[InlineData(2021, 13, DayOfWeek.Monday, 1, 0)] //1st Monday in the 13th month of 2021 12AM public void GetDateByOccurrence_WithInvalidInput(int year, int month, DayOfWeek dayOfWeek, int hour, int dayOfWeekOccurrence) { //Given a date defined by invalid occurrence //When I create the date Action act = () => DayCounterHelper.GetDateByOccurrence(year, month, dayOfWeek, dayOfWeekOccurrence, 0); //Then I should not be able to create the date Assert.Throws <ArgumentOutOfRangeException>(act); }
[InlineData(2021, 3, DayOfWeek.Wednesday, 5, 0, "31/03/2021")] //5th Wednesday of March 2021 AM public void GetDateByOccurrence_WithValidInput(int year, int month, DayOfWeek dayOfWeek, int dayOfWeekOccurrence, int hour, string expectedDateTime) { //Given a date defined by valid occurrence //When I create the date DateTime actualDateTime = DayCounterHelper.GetDateByOccurrence(year, month, dayOfWeek, dayOfWeekOccurrence, hour); //Then I should create the correct date Assert.Equal(DateTime.ParseExact(expectedDateTime, "d/M/yyyy", CultureInfo.InvariantCulture).Date, actualDateTime.Date); }
//Queen's Birthday public DateTime QueensBirthday(int year) { //Generate a date based on an occurrence //0 represents 12AM hour return(DayCounterHelper.GetDateByOccurrence(year, 6, DayOfWeek.Monday, 2, 0)); }
//Example of a Occurrence Public Holiday that is a half day //A half public holiday is defined as a date with the time set to 12PM public DateTime HalfDay(int year) { //Generate a date based on an occurrence //The 4th Monday of March return(DayCounterHelper.GetDateByOccurrence(year, 3, DayOfWeek.Monday, 4, 12)); }