Inheritance: DayTimeRange
Esempio n. 1
0
        public void GetNextDayTest() {
            var now = ClockProxy.Clock.Now;
            var day = new DayRange(now);

            day.GetNextDay().Should().Be(day.AddDays(1));
            day.GetNextDay().Start.Should().Be(now.Date.AddDays(1));
        }
Esempio n. 2
0
        public void DayOfWeekTest() {
            var now = ClockProxy.Clock.Now;
            var timeCalendar = new TimeCalendar();

            var day = new DayRange(now, timeCalendar);
            day.DayOfWeek.Should().Be(timeCalendar.Culture.Calendar.GetDayOfWeek(now));
        }
Esempio n. 3
0
        public DaySeekerContext(DayRange startDay, int dayCount) {
            startDay.ShouldNotBeNull("startDay");

            StartDay = startDay;
            DayCount = Math.Abs(dayCount);
            RemaingDays = DayCount;
        }
Esempio n. 4
0
        public void GetNextDayTest()
        {
            var now = ClockProxy.Clock.Now;
            var day = new DayRange(now);

            day.GetNextDay().Should().Be(day.AddDays(1));
            day.GetNextDay().Start.Should().Be(now.Date.AddDays(1));
        }
Esempio n. 5
0
        public void ConstructorTest() {
            var now = ClockProxy.Clock.Now;

            var day = new DayRange(now);
            day.Start.Should().Be(now.Date);

            day = new DayRange(now.Year, now.Month, now.Day);
            day.Start.Should().Be(now.Date);
        }
Esempio n. 6
0
        public void DayOfWeekTest()
        {
            var now          = ClockProxy.Clock.Now;
            var timeCalendar = new TimeCalendar();

            var day = new DayRange(now, timeCalendar);

            day.DayOfWeek.Should().Be(timeCalendar.Culture.Calendar.GetDayOfWeek(now));
        }
Esempio n. 7
0
        public void ProcessDay(DayRange day) {
            if(IsFinished)
                return;

            RemaingDays -= 1;

            if(IsFinished)
                FoundDay = day;
        }
Esempio n. 8
0
        public void InitValuesTest() {
            var now = ClockProxy.Clock.Now;
            var firstDay = new DateTime(now.Year, now.Month, now.Day);
            var secondDay = firstDay.AddDays(1);

            var day = new DayRange(now, TimeCalendar.NewEmptyOffset());

            day.Start.Should().Be(firstDay);
            day.End.Should().Be(secondDay);
        }
Esempio n. 9
0
        public void ConstructorTest()
        {
            var now = ClockProxy.Clock.Now;

            var day = new DayRange(now);

            day.Start.Should().Be(now.Date);

            day = new DayRange(now.Year, now.Month, now.Day);
            day.Start.Should().Be(now.Date);
        }
Esempio n. 10
0
        public void InitValuesTest()
        {
            var now       = ClockProxy.Clock.Now;
            var firstDay  = new DateTime(now.Year, now.Month, now.Day);
            var secondDay = firstDay.AddDays(1);

            var day = new DayRange(now, TimeCalendar.NewEmptyOffset());

            day.Start.Should().Be(firstDay);
            day.End.Should().Be(secondDay);
        }
Esempio n. 11
0
        public void AddDaysTest()
        {
            var now     = ClockProxy.Clock.Now;
            var nowDate = now.Date;

            var day = new DayRange(now, TimeCalendar.NewEmptyOffset());

            day.AddDays(0).Should().Be(day);

            Enumerable
            .Range(-60, 120)
            .RunEach(i => day.AddDays(i).Start.Should().Be(nowDate.AddDays(i)));
        }
Esempio n. 12
0
        public void SimpleForwardTest() {
            var start = new DayRange();
            var daySeeker = new DaySeeker();

            var day1 = daySeeker.FindDay(start, 0);
            day1.IsSamePeriod(start).Should().Be.True();

            var day2 = daySeeker.FindDay(start, 1);
            day2.IsSamePeriod(start.GetNextDay()).Should().Be.True();

            Enumerable
                .Range(-10, 20)
                .RunEach(i => {
                             var offset = i * 5;
                             var day = daySeeker.FindDay(start, offset);
                             day.IsSamePeriod(start.AddDays(offset)).Should().Be.True();
                         });
        }
Esempio n. 13
0
        public void GetHoursTest()
        {
            var day = new DayRange();

            var hours = day.GetHours();

            Assert.IsNotNull(hours);

            var index = 0;

            foreach (var hour in hours)
            {
                hour.Start.Should().Be(day.Start.AddHours(index));
                hour.End.Should().Be(hour.TimeCalendar.MapEnd(hour.Start.AddHours(1)));
                index++;
            }
            index.Should().Be(TimeSpec.HoursPerDay);
        }
Esempio n. 14
0
        public void DefaultCalendarTest() {
            var yearStart = new DateTime(ClockProxy.Clock.Now.Year, January, 1);

            for(var m = 1; m <= TimeSpec.MonthsPerYear; m++) {
                var monthStart = new DateTime(yearStart.Year, m, 1);
                var monthEnd = monthStart.EndTimeOfMonth().StartTimeOfDay();

                for(var monthDay = monthStart.Day; monthDay < monthEnd.Day; monthDay++) {
                    var day = new DayRange(monthStart.AddDays(monthDay - monthStart.Day));

                    day.Year.Should().Be(yearStart.Year);
                    day.Month.Should().Be(monthStart.Month);
                    day.Month.Should().Be(monthEnd.Month);
                    day.Day.Should().Be(monthDay);

                    day.Start.Should().Be(monthStart.AddDays(monthDay - monthStart.Day).Add(day.TimeCalendar.StartOffset));
                    day.End.Should().Be(monthStart.AddDays(monthDay).Add(day.TimeCalendar.EndOffset));
                }
            }
        }
Esempio n. 15
0
        public void SimpleBackwardTest() {
            var start = new DayRange();
            var daySeeker = new DaySeeker(SeekDirection.Backward);


            var day1 = daySeeker.FindDay(start, 0);
            day1.IsSamePeriod(start).Should().Be.True();


            var day2 = daySeeker.FindDay(start, 1);
            day2.IsSamePeriod(start.GetPreviousDay()).Should().Be.True();

            Enumerable
                .Range(-10, 20)
                .RunEach(i => {
                             var offset = i * 5;
                             var day = daySeeker.FindDay(start, offset);
                             day.IsSamePeriod(start.AddDays(-offset)).Should().Be.True();
                         });
        }
Esempio n. 16
0
        public void DefaultCalendarTest()
        {
            var yearStart = new DateTime(ClockProxy.Clock.Now.Year, January, 1);

            for (var m = 1; m <= TimeSpec.MonthsPerYear; m++)
            {
                var monthStart = new DateTime(yearStart.Year, m, 1);
                var monthEnd   = monthStart.EndTimeOfMonth().StartTimeOfDay();

                for (var monthDay = monthStart.Day; monthDay < monthEnd.Day; monthDay++)
                {
                    var day = new DayRange(monthStart.AddDays(monthDay - monthStart.Day));

                    day.Year.Should().Be(yearStart.Year);
                    day.Month.Should().Be(monthStart.Month);
                    day.Month.Should().Be(monthEnd.Month);
                    day.Day.Should().Be(monthDay);

                    day.Start.Should().Be(monthStart.AddDays(monthDay - monthStart.Day).Add(day.TimeCalendar.StartOffset));
                    day.End.Should().Be(monthStart.AddDays(monthDay).Add(day.TimeCalendar.EndOffset));
                }
            }
        }
Esempio n. 17
0
        public void SeekDirectionTest() {
            var start = new DayRange();

            var daySeeker = new DaySeeker();

            Enumerable
                .Range(-10, 20)
                .RunEach(i => {
                             var offset = i * 5;
                             var day = daySeeker.FindDay(start, offset);
                             day.IsSamePeriod(start.AddDays(offset)).Should().Be.True();
                         });


            var backwardSeeker = new DaySeeker(SeekDirection.Backward);

            Enumerable
                .Range(-10, 20)
                .RunEach(i => {
                             var offset = i * 5;
                             var day = backwardSeeker.FindDay(start, offset);
                             day.IsSamePeriod(start.AddDays(-offset)).Should().Be.True();
                         });
        }
Esempio n. 18
0
        public void SeekWeekendHolidayTest() {
            var start = new DayRange(new DateTime(2011, 2, 15));

            var filter = new CalendarVisitorFilter();
            filter.AddWorkingWeekDays();
            filter.ExcludePeriods.Add(new DayRangeCollection(2011, 2, 27, 14)); // 14 days -> week 9 and 10

            var daySeeker = new DaySeeker(filter);

            var day1 = daySeeker.FindDay(start, 3); // wtihtin the same working week
            day1.IsSamePeriod(new DayRange(2011, 2, 18)).Should().Be.True();

            var day2 = daySeeker.FindDay(start, 4); // 주말(19,20) 제외 21일 월요일
            day2.IsSamePeriod(new DayRange(2011, 2, 21)).Should().Be.True();

            var day3 = daySeeker.FindDay(start, 10); // 2월27일부터 14일간 휴가로 제외 기간을 설정했음.
            day3.IsSamePeriod(new DayRange(2011, 3, 15)).Should().Be.True();
        }
Esempio n. 19
0
        public void GetHoursTest() {
            var day = new DayRange();

            var hours = day.GetHours();
            Assert.IsNotNull(hours);

            var index = 0;
            foreach(var hour in hours) {
                hour.Start.Should().Be(day.Start.AddHours(index));
                hour.End.Should().Be(hour.TimeCalendar.MapEnd(hour.Start.AddHours(1)));
                index++;
            }
            index.Should().Be(TimeSpec.HoursPerDay);
        }
Esempio n. 20
0
        public void AddDaysTest() {
            var now = ClockProxy.Clock.Now;
            var nowDate = now.Date;

            var day = new DayRange(now, TimeCalendar.NewEmptyOffset());

            day.AddDays(0).Should().Be(day);

            Enumerable
                .Range(-60, 120)
                .RunEach(i => day.AddDays(i).Start.Should().Be(nowDate.AddDays(i)));
        }