Exemple #1
0
        public void CanCalculateRelativeEndDateForYesterday([ValueSource("SampleDates")] DateTime today, [ValueSource("DayBeforeSampleDates")] DateTime yesterday)
        {
            var startBound = DateRangeBound.CreateUnboundedBound();
            var endBound   = DateRangeBound.CreateRelativeBound(-1, DateInterval.Day);
            var range      = new DateRange(startBound, endBound);

            Expect(range.GetEndDate(today), Is.EqualTo(yesterday), "A relative range of -1 day should always produce the day before 'today'");
        }
Exemple #2
0
        public void CanCalculateRelativeEndDateForTomorrow([ValueSource("SampleDates")] DateTime today, [ValueSource("DayAfterSampleDates")] DateTime tomorrow)
        {
            var startBound = DateRangeBound.CreateUnboundedBound();
            var endBound   = DateRangeBound.CreateRelativeBound(1, DateInterval.Day);
            var range      = new DateRange(startBound, endBound);

            Expect(range.GetEndDate(today), Is.EqualTo(tomorrow), "A relative range of 1 day should always produce the day after 'today'");
        }
Exemple #3
0
        public void CanCalculateRelativeEndDateForToday([ValueSource("SampleDates")] DateTime today)
        {
            var startBound = DateRangeBound.CreateUnboundedBound();
            var endBound   = DateRangeBound.CreateRelativeBound(0, DateInterval.Day);
            var range      = new DateRange(startBound, endBound);

            Expect(range.GetEndDate(today), Is.EqualTo(today), "A relative range of zero days should always produce today");
        }
        public void CanCalculateWindowTenYearsAfterRelativeDate(
            [ValueSource("SampleDates")] DateTime today,
            [ValueSource("SampleRelativeAmounts")] int relativeAmount,
            [ValueSource("AllDateInvervals")] DateInterval relativeInterval)
        {
            var startBound = DateRangeBound.CreateRelativeBound(relativeAmount, relativeInterval);
            var endBound   = DateRangeBound.CreateWindowBound(10, DateInterval.Year);
            var range      = new DateRange(startBound, endBound);

            Expect(range.GetEndDate(today), Is.EqualTo(range.GetStartDate(today).Value.AddYears(10)), "An ending window range of 10 years should always produce ten years after the start");
        }
        public void CanCalculateWindowOneYearBeforeRelativeDate(
            [ValueSource("SampleDates")] DateTime today,
            [ValueSource("SampleRelativeAmounts")] int relativeAmount,
            [ValueSource("AllDateInvervals")] DateInterval relativeInterval)
        {
            var startBound = DateRangeBound.CreateWindowBound(1, DateInterval.Year);
            var endBound   = DateRangeBound.CreateRelativeBound(relativeAmount, relativeInterval);
            var range      = new DateRange(startBound, endBound);

            Expect(range.GetStartDate(today), Is.EqualTo(range.GetEndDate(today).Value.AddYears(-1)), "A starting window range of 1 year should always produce one year before the end");
        }
        public void StartWindowIsValidWithEndingRelative(
            [ValueSource("SampleWindowAmounts")] int startAmount,
            [ValueSource("AllDateInvervals")] DateInterval startInterval,
            [ValueSource("SampleRelativeAmounts")] int endWindow,
            [ValueSource("AllDateInvervals")] DateInterval endInterval)
        {
            var startBound = DateRangeBound.CreateWindowBound(startAmount, startInterval);
            var endBound   = DateRangeBound.CreateRelativeBound(endWindow, endInterval);
            var range      = new DateRange(startBound, endBound);

            Expect(range.IsValid, Is.True, "A range from window to relative is always valid");
        }
Exemple #7
0
        public void CanCalculateRelativeStartDateForThisMonth([ValueSource("SampleDates")] DateTime today)
        {
            var startBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Month);
            var endBound   = DateRangeBound.CreateUnboundedBound();
            var range      = new DateRange(startBound, endBound);

            var startDate = range.GetStartDate(today);

            Expect(startDate.HasValue, Is.True, "Should have a start date");
            Expect(startDate.Value.Year, Is.EqualTo(today.Year), "A relative range of zero months should always produce the same year");
            Expect(startDate.Value.Month, Is.EqualTo(today.Month), "A relative range of zero months should always produce the same month");
            Expect(startDate.Value.Day, Is.EqualTo(1), "A starting relative range of zero months should produce the first day of the month");
        }
Exemple #8
0
        public void CanCalculateRelativeEndDateForNextYear([ValueSource("SampleDates")] DateTime today)
        {
            var startBound = DateRangeBound.CreateUnboundedBound();
            var endBound   = DateRangeBound.CreateRelativeBound(1, DateInterval.Year);
            var range      = new DateRange(startBound, endBound);

            var endDate = range.GetEndDate(today);

            Expect(endDate.HasValue, Is.True, "Should have a start date");
            Expect(endDate.Value.Year, Is.EqualTo(today.AddYears(1).Year), "A relative range of 1 year should always produce the year after 'today'");
            Expect(endDate.Value.Month, Is.EqualTo(12), "An ending relative range of years should always produce December");
            Expect(endDate.Value.Day, Is.EqualTo(31), "An ending relative range of years should always produce December 31");
        }
Exemple #9
0
        public void CanCalculateRelativeStartDateForLastYear([ValueSource("SampleDates")] DateTime today)
        {
            var startBound = DateRangeBound.CreateRelativeBound(-1, DateInterval.Year);
            var endBound   = DateRangeBound.CreateUnboundedBound();
            var range      = new DateRange(startBound, endBound);

            var startDate = range.GetStartDate(today);

            Expect(startDate.HasValue, Is.True, "Should have a start date");
            Expect(startDate.Value.Year, Is.EqualTo(today.AddYears(-1).Year), "A relative range of -1 years should always produce the year before 'today'");
            Expect(startDate.Value.Month, Is.EqualTo(1), "A starting relative range of years should always produce January");
            Expect(startDate.Value.Day, Is.EqualTo(1), "A starting relative range of years should always produce January 1");
        }
Exemple #10
0
        public void CanCalculateRelativeEndDateForNextMonth([ValueSource("SampleDates")] DateTime today)
        {
            var startBound = DateRangeBound.CreateUnboundedBound();
            var endBound   = DateRangeBound.CreateRelativeBound(1, DateInterval.Month);
            var range      = new DateRange(startBound, endBound);

            var endDate = range.GetEndDate(today);

            Expect(endDate.HasValue, Is.True, "Should have a start date");
            Expect(endDate.Value.Year, Is.EqualTo(today.AddMonths(1).Year), "A relative range of 1 month should always produce the month after 'today'");
            Expect(endDate.Value.Month, Is.EqualTo(today.AddMonths(1).Month), "A relative range of 1 month should always produce the month after 'today'");
            Expect(endDate.Value.Day, Is.EqualTo(GetLastDayOfMonth(today.AddMonths(1)).Day), "A relative range of 1 month should always produce the last day of the month after 'today'");
        }