[InlineData("2021-10-07 10:00:00", "2021-10-05 10:00:00", 2)]//Normal work day public void GetDateForANumberOfWorkdaysAgo(string date, string expected, int numberOfAddedDays) { using var tolkDbContext = CreateTolkDbContext(DbNameWithHolidays); var subject = new DateCalculationService(CreateCacheService(tolkDbContext)); subject.GetDateForANumberOfWorkdaysAgo(DateTime.Parse(date), numberOfAddedDays).Should().Be(DateTime.Parse(expected)); }
public RequestController( TolkDbContext dbContext, ISwedishClock clock, IAuthorizationService authorizationService, PriceCalculationService priceCalculationService, DateCalculationService dateCalculationService, ILogger <RequestController> logger, IOptions <TolkOptions> options, RequestService requestService, InterpreterService interpreterService, ListToModelService listToModelService, EventLogService eventLogService, CacheService cacheService) { _dbContext = dbContext; _clock = clock; _authorizationService = authorizationService; _priceCalculationService = priceCalculationService; _dateCalculationService = dateCalculationService; _logger = logger; _options = options.Value; _requestService = requestService; _interpreterService = interpreterService; _listToModelService = listToModelService; _eventLogService = eventLogService; _cacheService = cacheService; }
[InlineData("2018-09-05", "2018-09-05")]//Normal work day public void GetFirstWorkDay(string date, string expected) { using var tolkDbContext = CreateTolkDbContext(DbNameWithHolidays); var subject = new DateCalculationService(CreateCacheService(tolkDbContext)); subject.GetFirstWorkDay(DateTime.Parse(date)).Should().Be(DateTime.Parse(expected), "that is the first workday after {0}", date); }
[InlineData("2018-09-05", true)] //Normal work day public void IsWorkDay(string date, bool expected) { using var tolkDbContext = CreateTolkDbContext(DbNameWithHolidays); var subject = new DateCalculationService(CreateCacheService(tolkDbContext)); string errorMessage = expected ? "should be a workday" : "should not be a workday"; subject.IsWorkingDay(DateTime.Parse(date)).Should().Be(expected, "{0} {1}", date, errorMessage); }
[InlineData("2018-04-02 16:00:00", "2018-04-02 19:00:00", 0)] // Easter Friday (3h but non work day) public void GetNoOfHoursOfWorkDaysBetween(string firstDate, string secondDate, int actual) { using var tolkDbContext = CreateTolkDbContext(DbNameWithHolidays); var subject = new DateCalculationService(CreateCacheService(tolkDbContext)); subject.GetNoOfHoursOfWorkDaysBetween(DateTime.Parse(firstDate), DateTime.Parse(secondDate)) .Should().Be(actual, "there are {0} hours of workday time between {1} and {2}", actual, firstDate, secondDate); }
public void GetInvolvedYearsShouldReturnOneYearWhenStartAndEndAreEqual() { var start = new DateTime(2016, 01, 01, 0, 0, 0); var end = new DateTime(2016, 01, 01, 0, 0, 0); var result = new DateCalculationService().GetInvolvedYears(start, end); result.Should().HaveCount(1); }
public void GetCalendarWeekShouldReturnTheCorrectCalenderWeekForTheFirstDay() { var date = new DateTime(2016, 08, 28, 0, 0, 0); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de"); var cw = new DateCalculationService().GetCalendarWeek(date); cw.Should().Be(34); }
public void GetWorkDaysBetween_ThrowsIfFirstDateIsAfterSecondDate() { using var tolkDbContext = CreateTolkDbContext(); var subject = new DateCalculationService(CreateCacheService(tolkDbContext)); Action a = () => subject.GetWorkDaysBetween(new DateTime(1), new DateTime(0)); a.Should().Throw <ArgumentException>(); }
public void GetStartDateOfYearShouldReturnTheCorrectEndDateForTheLastDay() { var date = new DateTime(2016, 12, 31, 0, 0, 0); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de"); var endDate = new DateCalculationService().GetStartDateOfYear(date); endDate.ToString("dd.MM.yyyy HH:mm:ss").Should() .Be(new DateTime(2016, 01, 01, 0, 0, 0).ToString("dd.MM.yyyy HH:mm:ss")); }
public void GetEndDateOfMonthShouldReturnTheCorrectEndDate() { var date = new DateTime(2016, 08, 23, 0, 0, 0); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de"); var endDate = new DateCalculationService().GetEndDateOfMonth(date); endDate.ToString("dd.MM.yyyy HH:mm:ss").Should() .Be(new DateTime(2016, 08, 31, 23, 59, 59).ToString("dd.MM.yyyy HH:mm:ss")); }
public void GetWorkDaysBetween_ThrowsIfSecondDateIsNotPlainDate() { using var tolkDbContext = CreateTolkDbContext(); var subject = new DateCalculationService(CreateCacheService(tolkDbContext)); Action a = () => subject.GetWorkDaysBetween(new DateTime(2018, 06, 04), new DateTime(2018, 06, 05, 14, 00, 00)); a.Should().Throw <ArgumentException>() .And.ParamName.Should().Be("secondDate"); }
public void GetWorkDaysBetween_ThrowsDateTimeKindsAreDifferent() { using var tolkDbContext = CreateTolkDbContext(); var subject = new DateCalculationService(CreateCacheService(tolkDbContext)); Action a = () => subject.GetWorkDaysBetween( new DateTime(2018, 5, 1, 0, 0, 0, DateTimeKind.Local), new DateTime(2018, 6, 1, 0, 0, 0, DateTimeKind.Unspecified)); a.Should().Throw <ArgumentException>(); }
public void GetInvolvedYearsShouldReturnCorrectResultWhenTwoDatesAreUsed() { var start = new DateTime(2016, 01, 01, 0, 0, 0); var end = new DateTime(2018, 01, 01, 0, 0, 0); var result = new DateCalculationService().GetInvolvedYears(start, end); result.Should().HaveCount(3); result.Should().Contain(new List <int>() { 2016, 2017, 2018 }); }
public void GetStartAndEndDateOfMonthShouldReturnTheCorrectStartAndEndDateForTheLastDay() { var date = new DateTime(2016, 08, 1, 0, 0, 0); DateTime endDate; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de"); var startDate = new DateCalculationService().GetStartAndEndDateOfMonth(date, out endDate); endDate.ToString("dd.MM.yyyy HH:mm:ss").Should() .Be(new DateTime(2016, 08, 31, 23, 59, 59).ToString("dd.MM.yyyy HH:mm:ss")); startDate.ToString("dd.MM.yyyy HH:mm:ss").Should() .Be(new DateTime(2016, 08, 1, 0, 0, 0).ToString("dd.MM.yyyy HH:mm:ss")); }
public void GetStartAndEndDateOfQuarterShouldReturnTheCorrectQuarterForTheFirstDay() { var date = new DateTime(2016, 08, 31, 0, 0, 0); DateTime endDate; int quarter; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de"); var startDate = new DateCalculationService().GetStartAndEndDateOfQuarter(date, out endDate, out quarter); endDate.ToString("dd.MM.yyyy HH:mm:ss").Should() .Be(new DateTime(2016, 09, 30, 23, 59, 59).ToString("dd.MM.yyyy HH:mm:ss")); startDate.ToString("dd.MM.yyyy HH:mm:ss").Should() .Be(new DateTime(2016, 07, 1, 0, 0, 0).ToString("dd.MM.yyyy HH:mm:ss")); quarter.Should().Be(3); }