コード例 #1
0
 public void WhenEndBeforeStart_ThenRangeRhrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(
         () => DateRange.DayRange(
             new DateTime(2020, 1, 2, 0, 0, 0),
             new DateTime(2020, 1, 1, 0, 0, 0),
             1).ToList());
 }
コード例 #2
0
        public void WhenStepPassesEndAndStepIsPositive_ThenRangeExcludesEnd()
        {
            var range = DateRange.DayRange(
                new DateTime(2020, 1, 1, 0, 0, 0),
                new DateTime(2020, 1, 4, 0, 0, 0),
                2).ToList();

            Assert.AreEqual(2, range.Count());
            Assert.AreEqual(new DateTime(2020, 1, 1, 0, 0, 0), range[0]);
            Assert.AreEqual(new DateTime(2020, 1, 3, 0, 0, 0), range[1]);
        }
コード例 #3
0
        public void WhenStepPassesEndAndStepIsNegative_ThenRangeExcludesEnd()
        {
            var range = DateRange.DayRange(
                new DateTime(2020, 1, 10, 0, 0, 0),
                new DateTime(2020, 1, 5, 0, 0, 0),
                -2).ToList();

            Assert.AreEqual(3, range.Count());
            Assert.AreEqual(new DateTime(2020, 1, 10, 0, 0, 0), range[0]);
            Assert.AreEqual(new DateTime(2020, 1, 8, 0, 0, 0), range[1]);
            Assert.AreEqual(new DateTime(2020, 1, 6, 0, 0, 0), range[2]);
        }
コード例 #4
0
        public void WhenStartLessThanEnd_ThenRangeContainsAllDaysIncludingBounds()
        {
            var range = DateRange.DayRange(
                new DateTime(2020, 1, 1, 0, 0, 0),
                new DateTime(2020, 1, 3, 0, 0, 0),
                1).ToList();

            Assert.AreEqual(3, range.Count());
            Assert.AreEqual(new DateTime(2020, 1, 1, 0, 0, 0), range[0]);
            Assert.AreEqual(new DateTime(2020, 1, 2, 0, 0, 0), range[1]);
            Assert.AreEqual(new DateTime(2020, 1, 3, 0, 0, 0), range[2]);
        }
コード例 #5
0
        public void WhenStartEqualsEnd_ThenRangeContainsSingleRange()
        {
            var range = DateRange.DayRange(
                new DateTime(2020, 1, 1, 0, 0, 0),
                new DateTime(2020, 1, 1, 2, 3, 4),
                1);

            Assert.AreEqual(1, range.Count());
            Assert.AreEqual(
                new DateTime(2020, 1, 1, 0, 0, 0),
                range.First());
        }