Ejemplo n.º 1
0
        public void Overlaps_With_Returns_False_When_The_Dates_Are_Not_Overlapping()
        {
            var Jan1 = DateRange.Day(new DateTime(2018, 1, 1));
            var Dec5 = DateRange.Day(new DateTime(2018, 12, 5));

            Jan1.OverlapsWith(Dec5).Should().BeFalse();
            Dec5.OverlapsWith(Jan1).Should().BeFalse();
        }
Ejemplo n.º 2
0
        public void IsInRangeIndexed_Returns_The_First_Index_Of_The_Range_That_Contains_The_Date()
        {
            var collection = new DateRangeCollection
            {
                DateRange.Year(2016),
                DateRange.Year(2017),
                DateRange.Year(2018),
                DateRange.Years(2018, 2),
                DateRange.Day(new DateTime(2019, 1, 1)),
            };

            collection.InRangeIndexed(new DateTime(2016, 6, 6)).Should().Be(0);
            collection.InRangeIndexed(new DateTime(2018, 6, 6)).Should().Be(2);
            collection.InRangeIndexed(new DateTime(2019, 1, 1)).Should().Be(3);
            collection.InRangeIndexed(new DateTime(2020, 1, 2)).Should().Be(-1);
        }
Ejemplo n.º 3
0
        public void Ordered_Collection()
        {
            var collection = new DateRangeCollection
            {
                DateRange.Always,
                DateRange.Year(2018),
                DateRange.Year(2017),
                DateRange.Years(2018, 2),
                DateRange.Day(new DateTime(2018, 1, 1)),
                DateRange.Days(new DateTime(2018, 1, 1), 2),
                DateRange.Never
            };

            var ordered = collection.Ordered();

            ordered[0].Should().Be(DateRange.Never);
            ordered[1].Should().Be(DateRange.Always);
            ordered[2].Should().Be(DateRange.Year(2017));
            ordered[3].Should().Be(DateRange.Day(new DateTime(2018, 1, 1)));
            ordered[4].Should().Be(DateRange.Days(new DateTime(2018, 1, 1), 2));
            ordered[5].Should().Be(DateRange.Year(2018));
            ordered[6].Should().Be(DateRange.Years(2018, 2));
        }
Ejemplo n.º 4
0
        public void Order_Collection_By_Comparer()
        {
            var list = new List <DateRange>
            {
                DateRange.Always,
                DateRange.Year(2018),
                DateRange.Year(2017),
                DateRange.Years(2018, 2),
                DateRange.Day(new DateTime(2018, 1, 1)),
                DateRange.Days(new DateTime(2018, 1, 1), 2),
                DateRange.Never
            };

            var ordered = list.OrderBy(x => x, new DateRangeComparer()).ToList();

            ordered[0].Should().Be(DateRange.Never);
            ordered[1].Should().Be(DateRange.Always);
            ordered[2].Should().Be(DateRange.Year(2017));
            ordered[3].Should().Be(DateRange.Day(new DateTime(2018, 1, 1)));
            ordered[4].Should().Be(DateRange.Days(new DateTime(2018, 1, 1), 2));
            ordered[5].Should().Be(DateRange.Year(2018));
            ordered[6].Should().Be(DateRange.Years(2018, 2));
        }
Ejemplo n.º 5
0
 public void DateRange_For_Day_Can_Inline_Year_Month_Day()
 {
     DateRange.Day(2018, 1, 1).Should().Be(DateRange.Day(new DateTime(2018, 1, 1)));
 }
Ejemplo n.º 6
0
        public void IsInRange_Returns_True_When_The_Date_Has_A_Time_Portion()
        {
            var sut = DateRange.Day(new DateTime(2018, 1, 1));

            sut.IsInRange(new DateTime(2018, 1, 1, 23, 59, 59)).Should().BeTrue();
        }
Ejemplo n.º 7
0
        public void Day_Creates_A_Range_That_Spans_One_Day()
        {
            var sut = DateRange.Day(DateTime.Today);

            sut.Should().Be(DateRange.Today());
        }