public void Constructor() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, null); var checker = new OpenTimeChecker(filteredPeriods); Assert.Same(checker.Periods, filteredPeriods); }
public void FilterListByType() { Assert.Empty(OpenTimePeriodReader.FilterListByType(listOfAll, null)); var filterOnTest1 = OpenTimePeriodReader.FilterListByType(listOfAll, "test1"); Assert.Single(filterOnTest1); Assert.True(filterOnTest1[0].Name == "Test Open Time Period 1"); var filterOnTest2 = OpenTimePeriodReader.FilterListByType(listOfAll, "test2"); Assert.Equal(2, filterOnTest2.Count); var names2 = filterOnTest2.Select(x => x.Name); Assert.Contains("Test Open Time Period 1", names2); Assert.Contains("Test Open Time Period 2", names2); var filterOnTest3 = OpenTimePeriodReader.FilterListByType(listOfAll, "test3"); Assert.Equal(2, filterOnTest3.Count); var names3 = filterOnTest3.Select(x => x.Name); Assert.Contains("Test Open Time Period 2", names3); Assert.Contains("Test Open Time Period 3", names3); }
public void GetMostApplicableTimePeriod() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, "test1"); var checker = new OpenTimeChecker(filteredPeriods); var june5 = DateTime.Parse("2018-06-05"); // Tuesday should be Test 2 Assert.Equal("Test Open Time Period 2", checker.GetMostApplicableTimePeriod(june5).Name); }
public void IsOpen_OutNextTimeOpen1() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, "test1"); var checker = new OpenTimeChecker(filteredPeriods); // 1st Jan is Monday, so next should open at 9:00 var checkTime = DateTime.Parse("2018-01-01 08:30:00"); Assert.False(checker.IsOpen(checkTime, out DateTime? nextTime)); Assert.Equal(DateTime.Parse("2018-01-01 09:00:00"), nextTime); }
public void GetOpenTimesForDay() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, "test1"); var checker = new OpenTimeChecker(filteredPeriods); var june5 = DateTime.Parse("2018-06-05"); // Tuesday should be Test 2 var times = checker.GetOpenTimesForDay(june5); Assert.Single(times); Assert.Equal("8:00", times[0].Start); Assert.Equal("12:30", times[0].End); }
public void IsOpen_OutNextTimeOpen2() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, "test3"); var checker = new OpenTimeChecker(filteredPeriods); // Boxing day is a Wednesday , so closed according to Test 2 // The next open should be Monday 31 Dec at 9am (according to Test 2 var boxingDayLunch = DateTime.Parse("2018-12-26 12:00:00"); Assert.False(checker.IsOpen(boxingDayLunch, out DateTime? nextTime)); Assert.Equal(DateTime.Parse("2018-12-31 09:00:00"), nextTime); }
public void IsOpen_OutNextTimeClosed1() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, "test3"); var checker = new OpenTimeChecker(filteredPeriods); // Christmas is a Tuesday so open according to Test 4 // Next time should same day at 12:30 because that is Tuesday closing time var christmasLunch = DateTime.Parse("2018-12-25 12:00:00"); Assert.True(checker.IsOpen(christmasLunch, out DateTime? nextTime)); Assert.Equal(DateTime.Parse("2018-12-25 12:30:00"), nextTime); }
public void IsOpen_OutName() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, "test3"); var checker = new OpenTimeChecker(filteredPeriods); // Christmas is a Tuesday var christmasLunch = DateTime.Parse("2018-12-25 12:00:00"); Assert.True(checker.IsOpen(christmasLunch, out string xDayLunchPeriod)); Assert.Equal("Test Open Time Period 4", xDayLunchPeriod); // Boxing day is a Wednesday , so closed according to Test 2 // Even though Test 3 says is open (has lower Priority) var boxingDayLunch = DateTime.Parse("2018-12-26 12:00:00"); Assert.False(checker.IsOpen(boxingDayLunch, out string boxDayLunchPeriod)); Assert.Equal("Test Open Time Period 2", boxDayLunchPeriod); }
public void IsOpen() { var filteredPeriods = OpenTimePeriodReader.FilterListByType(allPeriods, "test1"); var checker = new OpenTimeChecker(filteredPeriods); var mayDay = DateTime.Parse("2018-05-07"); var otherMayMondays = new List <DateTime> { DateTime.Parse("2018-05-14 09:00:00"), DateTime.Parse("2018-05-21 16:59:59"), DateTime.Parse("2018-05-28 16:59:59"), }; Assert.False(checker.IsOpen(mayDay)); otherMayMondays.ForEach(x => Assert.True(checker.IsOpen(x))); // 5 June is a Tuesday so should be test2 overriding and closed by 12:30 var june5am = DateTime.Parse("2018-06-05 08:00:00"); var june5pm = DateTime.Parse("2018-06-05 12:30:01"); Assert.True(checker.IsOpen(june5am)); Assert.False(checker.IsOpen(june5pm)); }