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 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 BusinessDaysBetweenTwoDates_ShouldReturnCorrectResult(int[] firstDataSet, int[] secondDataSet, int expected) { var firstDate = ArrayToDate(firstDataSet); var secondDate = ArrayToDate(secondDataSet); var result = businessDayCounter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays); Assert.Equal(expected, result); }
public void BusinessDaysBetweenTwoDatesReturns0WhenSecondEqualsFirst() { var firstDate = DateTime.Now; var secondDate = firstDate; var publicHols = new List <DateTime>(); int expectedResult = 0; var actualResult = _counter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHols); Assert.Equal(expectedResult, actualResult); }
public void TestBusinessDaysBetweenTwoDates() { DateTime first = new DateTime(2013, 10, 7); DateTime second = new DateTime(2014, 1, 1); List <DateTime> holidays = new List <DateTime>(); holidays.Add(new DateTime(2013, 12, 25)); holidays.Add(new DateTime(2013, 12, 26)); holidays.Add(new DateTime(2014, 1, 1)); int weekdays = BusinessDayCounter.BusinessDaysBetweenTwoDates(first, second, holidays); Assert.AreEqual(weekdays, 59); }
public void CalculateBusinessDaysBetweenTwoDates(DateTime firstDate, DateTime secondDate, int expectedResults) { var holidays = new List <DateTime> { new DateTime(2013, 12, 25), new DateTime(2013, 12, 26), new DateTime(2014, 1, 1) }; //var results = counter.BusinessDaysBetweenTwoDates(firstDate, secondDate, holidays); var results = counter.BusinessDaysBetweenTwoDates(firstDate, secondDate, holidays); Assert.AreEqual(expectedResults, results); }
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 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 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 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 BusinessDaysBetweenTwoDatesReturnsCorrectNumDays() { //Arrange var expected = 1; var startDate = new DateTime(2013, 10, 07); var endDate = new DateTime(2013, 10, 09); var expectedCase2 = 0; var startDateCase2 = new DateTime(2013, 12, 24); var endDateCase2 = new DateTime(2013, 12, 27); var expectedCase3 = 59; var startDateCase3 = new DateTime(2013, 10, 07); var endDateCase3 = new DateTime(2014, 01, 01); //Act var actual = _businessDaysService.BusinessDaysBetweenTwoDates(startDate, endDate, sampleHolidays); var actualCase2 = _businessDaysService.BusinessDaysBetweenTwoDates(startDateCase2, endDateCase2, sampleHolidays); var actualCase3 = _businessDaysService.BusinessDaysBetweenTwoDates(startDateCase3, endDateCase3, sampleHolidays); //Assert Assert.AreEqual(expected, actual); Assert.AreEqual(expectedCase2, actualCase2); Assert.AreEqual(expectedCase3, actualCase3); }
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 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 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 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 int TestBusinessDaysBetweenTwoDatesWithPublicHolidays(DateTime startDate, DateTime endDate, IList <AnnualPublicHoliday> publicHolidays) { var underTest = new BusinessDayCounter(); return(underTest.BusinessDaysBetweenTwoDates(startDate, endDate, publicHolidays)); }
public void BusinessDaysBetweenTwoDates_GivesExpectedResult(DateTime firstDate, DateTime secondDate, IList <DateTime> publicHolidays, int expectedResult) { var weekdays = _businessDayCounter.BusinessDaysBetweenTwoDates(firstDate, secondDate, publicHolidays); Assert.Equal(weekdays, expectedResult); }
public void BusinessDaysBetweenTwoDates_Should_Return_Expected_Data_When_Receive_Customized_Holidays() { //Arrange var dateCounter = new BusinessDayCounter(); var publicHolidays = new List <PublicHoliday>(); publicHolidays.Add(new PublicHoliday() { Type = PublicHolidayType.SameDay, DateOcurrence = new DateOcurrence() { Day = 25, Month = Month.Apr }, Name = "Anzac Day" }); publicHolidays.Add(new PublicHoliday() { Type = PublicHolidayType.MondayIfWeekend, DateOcurrence = new DateOcurrence() { Day = 1, Month = Month.Jan }, Name = "New Year's Day" }); publicHolidays.Add(new PublicHoliday() { Type = PublicHolidayType.ByOcurrence, DateOcurrence = new DateOcurrence() { Type = OcurrenceType.Second, WeekDay = DayOfWeek.Monday, Month = Month.Jun }, Name = "Queens Birthday" }); publicHolidays.Add(new PublicHoliday() { Type = PublicHolidayType.FixedDate, Date = new DateTime(2013, 9, 6), Name = "Random Date" }); var startDate1 = new DateTime(2013, 4, 24); var endDate1 = new DateTime(2013, 4, 27); var startDate2 = new DateTime(2016, 12, 30); var endDate2 = new DateTime(2017, 1, 4); var startDate3 = new DateTime(2021, 6, 13); var endDate3 = new DateTime(2021, 6, 15); var startDate4 = new DateTime(2013, 1, 1); var endDate4 = 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); var businessDaysQty4 = dateCounter.BusinessDaysBetweenTwoDates(startDate4, endDate4, publicHolidays); //Assert Assert.AreEqual(1, businessDaysQty1); Assert.AreEqual(1, businessDaysQty2); Assert.AreEqual(0, businessDaysQty3); Assert.AreEqual(257, businessDaysQty4); }
public void FirstTestForBusinessDaysBetweenTwoDates() { int result = bdc.BusinessDaysBetweenTwoDates(new DateTime(2013, 10, 7), new DateTime(2013, 10, 9), seedData.PublicHolidays); Assert.That(result, Is.EqualTo(1)); }