PageRenderTime 35ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/HolidayCal/HolidayCalTests/HolidayCalendarTestsBase.cs

https://github.com/AndreasPresthammer/HolidayCal
C# | 51 lines | 41 code | 10 blank | 0 comment | 2 complexity | d163d481b1ed15a54ea3eef0e8b319c1 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using FluentAssertions;
  4. using HolidayCal;
  5. using NUnit.Framework;
  6. namespace HolidayCalTests
  7. {
  8. internal abstract class HolidayCalendarTestsBase
  9. {
  10. [Test]
  11. public void TestHolidays()
  12. {
  13. TestSample testSample = GetTestSample();
  14. foreach (DateTime date in GetDays(testSample.From, testSample.To))
  15. {
  16. Holiday holiday = GetTarget().GetHoliday(date);
  17. bool isHoliday = GetTarget().IsHoliday(date);
  18. if (testSample.Holidays.Contains(date))
  19. {
  20. holiday.Should().NotBeNull(string.Format("{0} should be a holiday", date.ToShortDateString()));
  21. isHoliday.Should().BeTrue();
  22. }
  23. else
  24. {
  25. holiday.Should().BeNull(string.Format("{0} should not be a holiday", date.ToShortDateString()));
  26. isHoliday.Should().BeFalse();
  27. }
  28. }
  29. }
  30. protected abstract IHolidayCalendar GetTarget();
  31. protected abstract TestSample GetTestSample();
  32. private static IEnumerable<DateTime> GetDays(DateTime from, DateTime to)
  33. {
  34. while (from < to)
  35. {
  36. yield return from;
  37. from = from.AddDays(1);
  38. }
  39. }
  40. }
  41. }