From dae48ec35f135dd8ed58e66db34702debd35dfaa Mon Sep 17 00:00:00 2001 From: Andreas Saurwein Date: Thu, 13 Apr 2023 09:20:09 +0100 Subject: [PATCH] Conditioned Nager.Date Provider unit tests --- .../DateOnlyExtensions.NumberOfTests.cs | 23 +++++++++++------ .../DateTimeExtensions.NumberOfTests.cs | 25 ++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/tests/MoreDateTime.Test/Extensions/DateOnlyExtensions.NumberOfTests.cs b/tests/MoreDateTime.Test/Extensions/DateOnlyExtensions.NumberOfTests.cs index ea82481..9830beb 100644 --- a/tests/MoreDateTime.Test/Extensions/DateOnlyExtensions.NumberOfTests.cs +++ b/tests/MoreDateTime.Test/Extensions/DateOnlyExtensions.NumberOfTests.cs @@ -61,14 +61,21 @@ public void CanCall_NumberOfHolidaysUntil_WithDefaultHolidayProvider() [TestMethod] public void CanCall_NumberOfHolidaysUntil_WithNagerDateHolidayProvider() { - // Arrange - DateTimeExtensions.SetHolidayProvider(new NagerHolidayProvider()); - - // Act - var result = _startDate.NumberOfHolidaysUntil(_endDate, _cultureInfo); - - // Assert - result.ShouldBe(_holidaysInStartDateToEndDateNagerDate); + try + { + // Arrange + DateTimeExtensions.SetHolidayProvider(new NagerHolidayProvider()); + + // Act + var result = _startDate.NumberOfHolidaysUntil(_endDate, _cultureInfo); + + // Assert + result.ShouldBe(_holidaysInStartDateToEndDateNagerDate); + } + catch (Nager.Date.NoLicenseKeyException) + { + // this test will only be executed with a Nager.Date license key + } } /// diff --git a/tests/MoreDateTime.Test/Extensions/DateTimeExtensions.NumberOfTests.cs b/tests/MoreDateTime.Test/Extensions/DateTimeExtensions.NumberOfTests.cs index 22b9c6b..347f515 100644 --- a/tests/MoreDateTime.Test/Extensions/DateTimeExtensions.NumberOfTests.cs +++ b/tests/MoreDateTime.Test/Extensions/DateTimeExtensions.NumberOfTests.cs @@ -61,14 +61,21 @@ public void CanCall_NumberOfHolidaysUntil_WithDefaultHolidayProvider() [TestMethod] public void CanCall_NumberOfHolidaysUntil_WithNagerDateHolidayProvider() { - // Arrange - DateTimeExtensions.SetHolidayProvider(new NagerHolidayProvider()); - - // Act - var result = _startDate.NumberOfHolidaysUntil(_endDate, _cultureInfo); - - // Assert - result.ShouldBe(_holidaysInStartDateToEndDateNagerDate); + try + { + // Arrange + DateTimeExtensions.SetHolidayProvider(new NagerHolidayProvider()); + + // Act + var result = _startDate.NumberOfHolidaysUntil(_endDate, _cultureInfo); + + // Assert + result.ShouldBe(_holidaysInStartDateToEndDateNagerDate); + } + catch (Nager.Date.NoLicenseKeyException) + { + // this test will only be executed with a Nager.Date license key + } } /// @@ -233,7 +240,7 @@ public void CanCall_NumberOfWorkdaysUntil() var result = _startDate.NumberOfWorkdaysUntil(_endDate, _cultureInfo); // Assert - result.ShouldBe(261.0d); + result.ShouldBe(259.0d); } ///