示例#1
0
        public void CalendarDaysTest()
        {
            const int startYear  = 2004;
            const int startMonth = 2;
            const int startDay   = 27;
            const int dayCount   = 5;
            var       days       = new DayRangeCollection(startYear, startMonth, startDay, dayCount);

            days.DayCount.Should().Be(dayCount);
            days.StartYear.Should().Be(startYear);
            days.StartMonth.Should().Be(startMonth);
            days.StartDay.Should().Be(startDay);
            days.EndYear.Should().Be(2004);
            days.EndMonth.Should().Be(3);
            days.EndDay.Should().Be(2);

            var dayList = days.GetDays().ToList();

            dayList.Count.Should().Be(dayCount);

            dayList[0].IsSamePeriod(new DayRange(2004, 2, 27)).Should().Be.True();
            dayList[1].IsSamePeriod(new DayRange(2004, 2, 28)).Should().Be.True();
            dayList[2].IsSamePeriod(new DayRange(2004, 2, 29)).Should().Be.True();
            dayList[3].IsSamePeriod(new DayRange(2004, 3, 1)).Should().Be.True();
            dayList[4].IsSamePeriod(new DayRange(2004, 3, 2)).Should().Be.True();

            var dayRanges = days.GetDays().ToList();

            for (var i = 0; i < dayCount; i++)
            {
                dayRanges[i].IsSamePeriod(new DayRange(days.Start.AddDays(i))).Should().Be.True();
            }
        }
        public void CalendarDaysTest() {
            const int startYear = 2004;
            const int startMonth = 2;
            const int startDay = 27;
            const int dayCount = 5;
            var days = new DayRangeCollection(startYear, startMonth, startDay, dayCount);

            days.DayCount.Should().Be(dayCount);
            days.StartYear.Should().Be(startYear);
            days.StartMonth.Should().Be(startMonth);
            days.StartDay.Should().Be(startDay);
            days.EndYear.Should().Be(2004);
            days.EndMonth.Should().Be(3);
            days.EndDay.Should().Be(2);

            var dayList = days.GetDays().ToList();
            dayList.Count.Should().Be(dayCount);

            dayList[0].IsSamePeriod(new DayRange(2004, 2, 27)).Should().Be.True();
            dayList[1].IsSamePeriod(new DayRange(2004, 2, 28)).Should().Be.True();
            dayList[2].IsSamePeriod(new DayRange(2004, 2, 29)).Should().Be.True();
            dayList[3].IsSamePeriod(new DayRange(2004, 3, 1)).Should().Be.True();
            dayList[4].IsSamePeriod(new DayRange(2004, 3, 2)).Should().Be.True();

            var dayRanges = days.GetDays().ToList();

            for(var i = 0; i < dayCount; i++)
                dayRanges[i].IsSamePeriod(new DayRange(days.Start.AddDays(i))).Should().Be.True();
        }
        public void SingleDaysTest() {
            const int startYear = 2004;
            const int startMonth = 2;
            const int startDay = 22;
            var days = new DayRangeCollection(startYear, startMonth, startDay, 1);

            days.DayCount.Should().Be(1);
            days.StartYear.Should().Be(startYear);
            days.StartMonth.Should().Be(startMonth);
            days.StartDay.Should().Be(startDay);
            days.EndYear.Should().Be(2004);
            days.EndMonth.Should().Be(2);
            days.EndDay.Should().Be(startDay);

            var dayList = days.GetDays().ToList();

            dayList.Count.Should().Be(1);
            dayList[0].IsSamePeriod(new DayRange(2004, 2, 22)).Should().Be.True();
        }
示例#4
0
        public void SingleDaysTest()
        {
            const int startYear  = 2004;
            const int startMonth = 2;
            const int startDay   = 22;
            var       days       = new DayRangeCollection(startYear, startMonth, startDay, 1);

            days.DayCount.Should().Be(1);
            days.StartYear.Should().Be(startYear);
            days.StartMonth.Should().Be(startMonth);
            days.StartDay.Should().Be(startDay);
            days.EndYear.Should().Be(2004);
            days.EndMonth.Should().Be(2);
            days.EndDay.Should().Be(startDay);

            var dayList = days.GetDays().ToList();

            dayList.Count.Should().Be(1);
            dayList[0].IsSamePeriod(new DayRange(2004, 2, 22)).Should().Be.True();
        }
        public void CalendarHoursTest(int dayCount) {
            var now = ClockProxy.Clock.Now;
            var days = new DayRangeCollection(now, dayCount);

            var startTime = now.Date.Add(days.TimeCalendar.StartOffset);
            var endTime = startTime.AddDays(dayCount).Add(days.TimeCalendar.EndOffset);

            days.Start.Should().Be(startTime);
            days.End.Should().Be(endTime);

            days.DayCount.Should().Be(dayCount);

            var items = days.GetDays().ToList();
            items.Count.Should().Be(dayCount);

            for(var i = 0; i < dayCount; i++) {
                items[i].Start.Should().Be(startTime.AddDays(i));
                items[i].End.Should().Be(days.TimeCalendar.MapEnd(startTime.AddDays(i + 1)));
                items[i].IsSamePeriod(new DayRange(days.Start.AddDays(i))).Should().Be.True();
            }
        }
示例#6
0
        public void CalendarHoursTest(int dayCount)
        {
            var now  = ClockProxy.Clock.Now;
            var days = new DayRangeCollection(now, dayCount);

            var startTime = now.Date.Add(days.TimeCalendar.StartOffset);
            var endTime   = startTime.AddDays(dayCount).Add(days.TimeCalendar.EndOffset);

            days.Start.Should().Be(startTime);
            days.End.Should().Be(endTime);

            days.DayCount.Should().Be(dayCount);

            var items = days.GetDays().ToList();

            items.Count.Should().Be(dayCount);

            for (var i = 0; i < dayCount; i++)
            {
                items[i].Start.Should().Be(startTime.AddDays(i));
                items[i].End.Should().Be(days.TimeCalendar.MapEnd(startTime.AddDays(i + 1)));
                items[i].IsSamePeriod(new DayRange(days.Start.AddDays(i))).Should().Be.True();
            }
        }
        public void CalendarGetGapTest() {
            // simmulation of some reservations
            var periods = new TimePeriodCollection
                          {
                              new DayRangeCollection(2011, 3, 7, 2),
                              new DayRangeCollection(2011, 3, 16, 2)
                          };

            // the overall search range
            var limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21));
            var days = new DayRangeCollection(limits.Start, limits.Duration.Days + 1);

            // limits의 내부이고, 주말인 DayRange를 추가합니다.
            var excludeDays = days.GetDays().Where(day => limits.HasInside(day) && day.DayOfWeek.IsWeekEnd());
            periods.AddAll(excludeDays.Cast<ITimePeriod>());

            var gapCalculator = new TimeGapCalculator<TimeRange>(new TimeCalendar());
            var gaps = gapCalculator.GetGaps(periods, limits);

            gaps.Count.Should().Be(4);
            gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), DurationUtil.Days(1))).Should().Be.True();
            gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), DurationUtil.Days(3))).Should().Be.True();
            gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), DurationUtil.Days(2))).Should().Be.True();
            gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), DurationUtil.Days(1))).Should().Be.True();
        }