public void BusinessDaysBetweenTwoDates_Should_Return_Expected_Data() { //Arrange var dateCounter = new BusinessDayCounter(); var publicHolidays = new List <DateTime>() { new DateTime(2013, 12, 25), new DateTime(2013, 12, 26), new DateTime(2014, 1, 1) }; var startDate1 = new DateTime(2013, 10, 7); var endDate1 = new DateTime(2013, 10, 9); var startDate2 = new DateTime(2013, 12, 24); var endDate2 = new DateTime(2013, 12, 27); var startDate3 = new DateTime(2013, 10, 7); var endDate3 = new DateTime(2014, 1, 1); //Act var businessDaysQty1 = dateCounter.BusinessDaysBetweenTwoDates(startDate1, endDate1, publicHolidays); var businessDaysQty2 = dateCounter.BusinessDaysBetweenTwoDates(startDate2, endDate2, publicHolidays); var businessDaysQty3 = dateCounter.BusinessDaysBetweenTwoDates(startDate3, endDate3, publicHolidays); //Assert Assert.AreEqual(1, businessDaysQty1); Assert.AreEqual(0, businessDaysQty2); Assert.AreEqual(59, businessDaysQty3); }
public void BusinessDaysBetweenTwoDates_With_valid_holidaRules_Should_return_weekdays([ValueSource("_testDataHolidayRules")] TestData testData) { var businessDayCounter = new BusinessDayCounter(); int result = businessDayCounter.BusinessDaysBetweenTwoDates(testData.StartDate, testData.EndDate, testData.Rules); Assert.IsTrue(result == testData.ExpectedResult); }
public void BusinessDaysBetweenTwoDatesWithHolidayListTest() { BusinessDayCounter counter = new BusinessDayCounter(); List <DateTime> publicHolidays = new List <DateTime> { new DateTime(2013, 12, 25), new DateTime(2013, 12, 26), new DateTime(2014, 1, 1) }; var firstDate = new DateTime(2013, 10, 7); var secondDate = new DateTime(2013, 10, 9); var expectedResult = 1; Assert.AreEqual(expectedResult, counter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays)); firstDate = new DateTime(2013, 12, 24); secondDate = new DateTime(2013, 12, 27); expectedResult = 0; Assert.AreEqual(expectedResult, counter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays)); firstDate = new DateTime(2013, 10, 7); secondDate = new DateTime(2014, 1, 1); expectedResult = 59; Assert.AreEqual(expectedResult, counter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays)); }
public void WeekdaysBetweenTwoDates_Should_Return_Expected_Data() { //Arrange var dateCounter = new BusinessDayCounter(); var startDate1 = new DateTime(2013, 10, 7); var endDate1 = new DateTime(2013, 10, 9); var startDate2 = new DateTime(2013, 10, 5); var endDate2 = new DateTime(2013, 10, 14); var startDate3 = new DateTime(2013, 10, 7); var endDate3 = new DateTime(2014, 1, 1); var startDate4 = new DateTime(2013, 10, 7); var endDate4 = new DateTime(2013, 10, 5); //Act var weekDaysQty1 = dateCounter.WeekdaysBetweenTwoDates(startDate1, endDate1); var weekDaysQty2 = dateCounter.WeekdaysBetweenTwoDates(startDate2, endDate2); var weekDaysQty3 = dateCounter.WeekdaysBetweenTwoDates(startDate3, endDate3); var weekDaysQty4 = dateCounter.WeekdaysBetweenTwoDates(startDate4, endDate4); //Assert Assert.AreEqual(1, weekDaysQty1); Assert.AreEqual(5, weekDaysQty2); Assert.AreEqual(61, weekDaysQty3); Assert.AreEqual(0, weekDaysQty4); }
public void GetBaseMondayDateTest(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { var actual = BusinessDayCounter.GetBaseMondayDate(new DateTime(year, month, day)); var expected = new DateTime(expectedYear, expectedMonth, expectedDay); Assert.That(actual, Is.EqualTo(expected)); }
public void WeekdaysBetweenTwoDates_With_valid_data_Should_return_weekdays(DateTime startDate, DateTime endDate, int expected) { var businessDayCounter = new BusinessDayCounter(); int result = businessDayCounter.WeekdaysBetweenTwoDates(startDate, endDate); Assert.IsTrue(result == expected); }
public void BusienssDaysBetweenTwoDatesWithHolidayRuleTest() { BusinessDayCounter counter = new BusinessDayCounter(); List <HolidayRule> holidayRules = new List <HolidayRule> { new HolidayRule(25, 4), new HolidayRule(1, 1, true), new HolidayRule(6, 2, DayOfWeek.Monday) }; var firstDate = new DateTime(2011, 12, 29); var secondDate = new DateTime(2012, 1, 3); var expectedResult = 1; Assert.AreEqual(expectedResult, counter.BusienssDaysBetweenTwoDates(firstDate, secondDate, holidayRules)); firstDate = new DateTime(2015, 4, 23); secondDate = new DateTime(2015, 4, 28); expectedResult = 2; Assert.AreEqual(expectedResult, counter.BusienssDaysBetweenTwoDates(firstDate, secondDate, holidayRules)); firstDate = new DateTime(2021, 6, 2); secondDate = new DateTime(2021, 6, 8); expectedResult = 3; Assert.AreEqual(expectedResult, counter.BusienssDaysBetweenTwoDates(firstDate, secondDate, holidayRules)); firstDate = new DateTime(2021, 6, 9); secondDate = new DateTime(2021, 6, 15); expectedResult = 2; Assert.AreEqual(expectedResult, counter.BusienssDaysBetweenTwoDates(firstDate, secondDate, holidayRules)); }
public void WeekdaysBetweenTwoDatesTest() { BusinessDayCounter counter = new BusinessDayCounter(); var firstDate = new DateTime(2013, 10, 7); var secondDate = new DateTime(2013, 10, 9); var expectedResult = 1; Assert.AreEqual(expectedResult, counter.WeekdaysBetweenTwoDates(firstDate, secondDate)); firstDate = new DateTime(2013, 10, 5); secondDate = new DateTime(2013, 10, 14); expectedResult = 5; Assert.AreEqual(expectedResult, counter.WeekdaysBetweenTwoDates(firstDate, secondDate)); firstDate = new DateTime(2013, 10, 7); secondDate = new DateTime(2014, 1, 1); expectedResult = 61; Assert.AreEqual(expectedResult, counter.WeekdaysBetweenTwoDates(firstDate, secondDate)); firstDate = new DateTime(2013, 10, 7); secondDate = new DateTime(2013, 10, 5); expectedResult = 0; Assert.AreEqual(expectedResult, counter.WeekdaysBetweenTwoDates(firstDate, secondDate)); }
public void CountBusinessDays_ValidInput_Calculated() { Assert.AreEqual(1, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2013, 10, 7), new DateTime(2013, 10, 9), HolidayTestData.PublicHolidayDates)); Assert.AreEqual(0, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2013, 12, 24), new DateTime(2013, 12, 27), HolidayTestData.PublicHolidayDates)); Assert.AreEqual(59, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2013, 10, 7), new DateTime(2014, 1, 1), HolidayTestData.PublicHolidayDates)); }
public void CountBusinessDays_DuplicateHolidays_DuplicateIgnored() { Assert.AreEqual(1, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2013, 10, 7), new DateTime(2013, 10, 9), HolidayTestData.DupPublicHolidayDates)); Assert.AreEqual(0, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2013, 12, 24), new DateTime(2013, 12, 27), HolidayTestData.DupPublicHolidayDates)); Assert.AreEqual(59, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2013, 10, 7), new DateTime(2014, 1, 1), HolidayTestData.DupPublicHolidayDates)); }
public void WeekdaysBetweenTwoDatesTest(DateTime firstDate, DateTime secondDate, Action <int> assertion) { var _publicHolidayProvider = new PublicHolidayProvider(); var businessDayCounter = new BusinessDayCounter(_publicHolidayProvider); var daysCount = businessDayCounter.WeekdaysBetweenTwoDates(firstDate, secondDate); assertion(daysCount); }
public void CountBusinessDayRules_ValidInput_Calculated() { Assert.AreEqual(0, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2015, 12, 24), new DateTime(2015, 12, 26), HolidayTestData.PublicHolidays)); Assert.AreEqual(257, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2014, 12, 31), new DateTime(2015, 12, 31), HolidayTestData.PublicHolidays)); Assert.AreEqual(83, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2017, 12, 31), new DateTime(2018, 4, 28), HolidayTestData.PublicHolidays)); Assert.AreEqual(4, BusinessDayCounter.BusinessDaysBetweenTwoDates(new DateTime(2015, 12, 24), new DateTime(2016, 1, 2), HolidayTestData.PublicHolidays)); }
public void WeekdaysBetweenTwoDatesReturns0WhenFirstAfterSecond() { var counter = new BusinessDayCounter(); var firstDate = DateTime.Now; var secondDate = firstDate.AddDays(-1); int expected = 0; var actual = counter.WeekdaysBetweenTwoDates(firstDate, secondDate); Assert.Equal(expected, actual); }
public void WeekdaysBetweenTwoDates_WhenDatesAreTheSame_ThenReturnZero() { var businessDayCounter = new BusinessDayCounter(); var date = new DateTime(2020, 12, 11); var expectedResult = 0; var result = businessDayCounter.WeekdaysBetweenTwoDates(date, date); Assert.AreEqual(expectedResult, result); }
public void WeekdaysBetweenTwoDates_WhenSecondDateIsOneDayMoreThenFirstDate_ThenReturnZero() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2020, 12, 10); var secondDate = new DateTime(2020, 12, 11); var expectedResult = 0; var result = businessDayCounter.WeekdaysBetweenTwoDates(firstDate, secondDate); Assert.AreEqual(expectedResult, result); }
public void WeekdaysBetweenTwoDates_WhenSecondDateIsTwoDaysMoreThenFirstDate_ThenReturnOne() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2013, 10, 07); var secondDate = new DateTime(2013, 10, 09); var expectedResult = 1; var result = businessDayCounter.WeekdaysBetweenTwoDates(firstDate, secondDate); Assert.AreEqual(expectedResult, result); }
public void BusinessDaysBetweenTwoDatesTest(DateTime firstDate, DateTime secondDate, IReadOnlyList <DateTime> publicHolidays, Action <int> assertion) { var _publicHolidayProvider = new Mock <IPublicHolidayProvider>(); var businessDayCounter = new BusinessDayCounter(_publicHolidayProvider.Object); var daysCount = businessDayCounter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays); assertion(daysCount); }
public void WeekdaysBetweenTwoDates_WhenDatesAreThreeMonthsApart_ThenReturn61() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2013, 10, 07); var secondDate = new DateTime(2014, 01, 01); var expectedResult = 61; var result = businessDayCounter.WeekdaysBetweenTwoDates(firstDate, secondDate); Assert.AreEqual(expectedResult, result); }
public void WeekdaysBetweenTwoDates_WhenTheYearIsNotALeapYear_ThenReturn261() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2018, 12, 31); var secondDate = new DateTime(2020, 01, 01); var expectedResult = 261; var result = businessDayCounter.WeekdaysBetweenTwoDates(firstDate, secondDate); Assert.AreEqual(expectedResult, result); }
public void WeekdaysBetweenTwoDates_WhereDatesHaveTime_ThenReturnFive() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2013, 10, 05, 12, 59, 30); var secondDate = new DateTime(2013, 10, 14, 10, 30, 30); var expectedResult = 5; var result = businessDayCounter.WeekdaysBetweenTwoDates(firstDate, secondDate); Assert.AreEqual(expectedResult, result); }
public void Task1_Calculate_Weekdays_Between_TwoDates(string firstDate, string secondDate, int expectedCount) { //Given two dates var testFirstDate = DateTime.ParseExact(firstDate, "d/M/yyyy", CultureInfo.InvariantCulture); var testSecondtDate = DateTime.ParseExact(secondDate, "d/M/yyyy", CultureInfo.InvariantCulture); //When I count the weekdays between the two dates var actualCount = BusinessDayCounter.WeekdaysBetweenTwoDates(testFirstDate, testSecondtDate); //Then the count should exclude weekends Assert.Equal(expectedCount, actualCount); }
public void CountWeekdays_ValidInput_Calculated() { Assert.AreEqual(5, BusinessDayCounter.WeekdaysBetweenTwoDates(new DateTime(2013, 10, 5), new DateTime(2013, 10, 14))); Assert.AreEqual(0, BusinessDayCounter.WeekdaysBetweenTwoDates(new DateTime(2019, 10, 25), new DateTime(2019, 10, 28))); Assert.AreEqual(1, BusinessDayCounter.WeekdaysBetweenTwoDates(new DateTime(2013, 10, 7), new DateTime(2013, 10, 9))); Assert.AreEqual(5, BusinessDayCounter.WeekdaysBetweenTwoDates(new DateTime(2013, 10, 5), new DateTime(2013, 10, 14))); Assert.AreEqual(61, BusinessDayCounter.WeekdaysBetweenTwoDates(new DateTime(2013, 10, 7), new DateTime(2014, 1, 1))); Assert.AreEqual(4, BusinessDayCounter.WeekdaysBetweenTwoDates(new DateTime(2015, 1, 8), new DateTime(2015, 1, 15))); }
public void TestCountBusinessDaysUsingRules() { var counter = new BusinessDayCounter(); var holidayRules = new List <IHolidayRule>() { new AlwaysOnSameDayRule { Day = 25, Month = 4 }, new AlwaysOnSameDayExceptOnWeekendsRule { Day = 1, Month = 1 }, new CertainOccurenceOfCertainDayInAMonthRule { DayOfWeek = DayOfWeek.Monday, Month = 6, WeekOfMonth = 2 }, new AlwaysOnSameDayRule { Day = 25, Month = 12 }, new AlwaysOnSameDayRule { Day = 26, Month = 12 }, }; var beginDate = new DateTime(2013, 10, 7); var endDate = new DateTime(2013, 10, 9); Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidayRules), 1); beginDate = new DateTime(2013, 12, 24); endDate = new DateTime(2013, 12, 27); Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidayRules), 0); beginDate = new DateTime(2013, 10, 7); endDate = new DateTime(2014, 1, 1); Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidayRules), 59); }
public void BusinessDaysBetweenTwoDates_WhenDatesIncludeChristmas_ThenReturn59() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2013, 10, 07); var secondDate = new DateTime(2014, 01, 01); IList <DateTime> publicHolidays = new List <DateTime>(); publicHolidays.Add(new DateTime(2013, 12, 25)); publicHolidays.Add(new DateTime(2013, 12, 26)); publicHolidays.Add(new DateTime(2014, 01, 01)); var expectedResult = 59; var result = businessDayCounter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays); Assert.AreEqual(expectedResult, result); }
public void BusinessDaysBetweenTwoDates_WhenRuleForChristmasBoxingDayAndNewYears_ThenReturnFour() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2020, 12, 23); var secondDate = new DateTime(2021, 01, 02); IList <DateTime> publicHolidays = new List <DateTime>(); publicHolidays.Add(new DateTime(2013, 12, 25)); publicHolidays.Add(new DateTime(2013, 12, 26)); publicHolidays.Add(new DateTime(2014, 01, 01)); var expectedResult = 4; var result = businessDayCounter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays); Assert.AreEqual(expectedResult, result); }
public void BusinessDaysBetweenTwoDates_WhenRuleQueensBirthday_ThenReturnOne() { var businessDayCounter = new BusinessDayCounter(); var firstDate = new DateTime(2020, 06, 07); var secondDate = new DateTime(2020, 06, 10); IList <DateTime> publicHolidays = new List <DateTime>(); publicHolidays.Add(new DateTime(2013, 12, 25)); publicHolidays.Add(new DateTime(2013, 12, 26)); publicHolidays.Add(new DateTime(2014, 01, 01)); var expectedResult = 1; var result = businessDayCounter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays); Assert.AreEqual(expectedResult, result); }
public void Task2_Calculate_BusinessDays_Between_TwoDates(string firstDate, string secondDate, double expectedCount) { //Given two dates and a list of public holidays var publicHolidays = new[] { new DateTime(2013, 12, 25), new DateTime(2013, 12, 26), new DateTime(2013, 10, 8, 12, 0, 0) }; var testFirstDate = DateTime.ParseExact(firstDate, "d/M/yyyy", CultureInfo.InvariantCulture); var testSecondtDate = DateTime.ParseExact(secondDate, "d/M/yyyy", CultureInfo.InvariantCulture); //When I count the business days between the two dates var actualCount = BusinessDayCounter.BusinessDaysBetweenTwoDates(testFirstDate, testSecondtDate, publicHolidays.ToList()); //Then the count should exclude weekends and public holidays Assert.Equal(expectedCount, actualCount); }
public void Task3_Calculate_BusinessDays_Between_TwoDates(string firstDate, string secondDate, double expectedCount) { //Given two dates and a list of public holidays rules var publicHolidaysRules = new PublicHolidaysRules[] { new FixedPublicHolidays(), new MovingPublicHolidays(), new OccurrencePublicHolidays() }; var testFirstDate = DateTime.ParseExact(firstDate, "d/M/yyyy", CultureInfo.InvariantCulture); var testSecondtDate = DateTime.ParseExact(secondDate, "d/M/yyyy", CultureInfo.InvariantCulture); //When I count the business days between the two dates var actualCount = BusinessDayCounter.BusinessDaysBetweenTwoDates(testFirstDate, testSecondtDate, publicHolidaysRules.ToList()); //Then the count should exclude weekends and public holidays Assert.Equal(expectedCount, actualCount); }
public void BusinessDayCounterIntegrationWithAnnualHolidaysTests() { var newYear = new FirstWeekdayHolidayShiftingDecorator(new FixedDateHolidaysFactory(1, 1)); var christmas = new FixedDateHolidaysFactory(12, 25); var boxing = new FixedDateHolidaysFactory(12, 26); var queenDay = new DayOfMonthHolidaysFactory(6, DayOfWeek.Monday, 2); var aggregator = new HolidaysAggregator(new List <IHolidaysFactory>() { newYear, christmas, boxing, queenDay }); var counter = new BusinessDayCounter(); Assert.That(counter.BusinessDaysBetweenTwoDates(new DateTime(2016, 12, 20), new DateTime(2018, 2, 1), aggregator), Is.EqualTo(291 - 6)); }
public void TestCountWeekdays() { var counter = new BusinessDayCounter(); var beginDate = new DateTime(2013, 10, 7); var endDate = new DateTime(2013, 10, 9); Assert.AreEqual(counter.WeekdaysBetweenTwoDates(beginDate, endDate), 1); beginDate = new DateTime(2013, 10, 5); endDate = new DateTime(2013, 10, 14); Assert.AreEqual(counter.WeekdaysBetweenTwoDates(beginDate, endDate), 5); beginDate = new DateTime(2013, 10, 7); endDate = new DateTime(2014, 1, 1); Assert.AreEqual(counter.WeekdaysBetweenTwoDates(beginDate, endDate), 61); beginDate = new DateTime(2013, 10, 7); endDate = new DateTime(2013, 10, 5); Assert.AreEqual(counter.WeekdaysBetweenTwoDates(beginDate, endDate), 0); }