예제 #1
0
        public void CalendarDateAdd1Test()
        {
            CultureTestData.Default
            .RunEach(culture => {
                var timeCalendar = new TimeCalendar(new TimeCalendarConfig
                {
                    Culture   = culture,
                    EndOffset = TimeSpan.Zero
                });

                var calendarDateAdd = new CalendarDateAdd(timeCalendar);

                //! 주중 8시~18시가 Working Time 이고, 4월 4일은 제외한다
                //
                calendarDateAdd.AddWorkingWeekDays();
                calendarDateAdd.ExcludePeriods.Add(new DayRange(2011, 4, 4, calendarDateAdd.TimeCalendar));
                calendarDateAdd.WorkingHours.Add(new HourRangeInDay(8, 18));

                var start = new DateTime(2011, 4, 1, 9, 0, 0);

                calendarDateAdd.Add(start, DurationUtil.Hours(22)).Should().Be(new DateTime(2011, 4, 6, 11, 0, 0));
                calendarDateAdd.Add(start, DurationUtil.Hours(22), SeekBoundaryMode.Fill).Should().Be(new DateTime(2011, 4,
                                                                                                                   6, 11, 0,
                                                                                                                   0));

                calendarDateAdd.Add(start, DurationUtil.Hours(29)).Should().Be(new DateTime(2011, 4, 7, 8, 0, 0));
                calendarDateAdd.Add(start, DurationUtil.Hours(29), SeekBoundaryMode.Fill).Should().Be(new DateTime(2011, 4,
                                                                                                                   6, 18, 0,
                                                                                                                   0));
            });
        }
예제 #2
0
        public void IQueryOver_AddIsOverlap_IsOverlap_HasRange()
        {
            var loaded =
                UnitOfWork.CurrentSession.QueryOver <User>().AddIsOverlap(
                    new TimeRange(DateTime.Now.AddHours(-1), DurationUtil.Hours(2)),
                    u => u.ActivePeriod.Start,
                    u => u.ActivePeriod.End);

            Assert.IsTrue(loaded.RowCount() > 0);
            loaded.List().RunEach(log.Debug);
        }
예제 #3
0
        public void IQueryable_AddIsOverlap_IsOverlap_HasRange()
        {
            var loaded =
                Users
                .AddIsOverlap(new TimeRange(DateTime.Now.AddHours(-1), DurationUtil.Hours(2)),
                              u => u.ActivePeriod.Start,
                              u => u.ActivePeriod.End)
                .ToList();

            Assert.IsTrue(loaded.Count > 0);
            loaded.RunEach(log.Debug);
        }
예제 #4
0
        public void ICriteria_AddIsOverlap_IsOverlap_HasPeriod()
        {
            var loaded =
                Repository <User> .CreateCriteria()
                .AddIsOverlap(new TimeRange(DateTime.Now.AddHours(-1), DurationUtil.Hours(2)),
                              "ActivePeriod.Start",
                              "ActivePeriod.End")
                .List <User>();

            Assert.IsTrue(loaded.Count > 0);
            loaded.RunEach(log.Debug);
        }
예제 #5
0
        public void QueryOverOf_AddIsOverlap_IsOverlap_HasRange()
        {
            var loaded =
                QueryOver.Of <User>()
                .AddIsOverlap(new TimeRange(DateTime.Now.AddHours(-1), DurationUtil.Hours(2)),
                              u => u.ActivePeriod.Start,
                              u => u.ActivePeriod.End)
                .GetExecutableQueryOver(UnitOfWork.CurrentSession);

            loaded.RowCount().Should().Be.GreaterThan(0);
            loaded.List().RunEach(log.Debug);
        }
예제 #6
0
        public void HourTest()
        {
            DurationUtil.Hour.Should().Be(TimeSpan.FromHours(1));

            DurationUtil.Hours(0).Should().Be(TimeSpan.Zero);
            DurationUtil.Hours(1).Should().Be(TimeSpan.FromHours(1));
            DurationUtil.Hours(2).Should().Be(TimeSpan.FromHours(2));
            DurationUtil.Hours(-1).Should().Be(TimeSpan.FromHours(-1));
            DurationUtil.Hours(-2).Should().Be(TimeSpan.FromHours(-2));

            DurationUtil.Hours(23).Should().Be(new TimeSpan(0, 23, 0, 0));
            DurationUtil.Hours(23, 22).Should().Be(new TimeSpan(0, 23, 22, 0));
            DurationUtil.Hours(23, 22, 55).Should().Be(new TimeSpan(0, 23, 22, 55));
            DurationUtil.Hours(23, 22, 55, 496).Should().Be(new TimeSpan(0, 23, 22, 55, 496));
        }
예제 #7
0
        public void CalendarDateAdd3Test()
        {
            var calendarDateAdd = new CalendarDateAdd();

            //! 주중 8:30~12:00, 13:30~18:00가 Working Time 이고, 4월 4일은 제외한다
            //
            calendarDateAdd.AddWorkingWeekDays();
            calendarDateAdd.ExcludePeriods.Add(new DayRange(2011, 4, 4, calendarDateAdd.TimeCalendar));
            calendarDateAdd.WorkingHours.Add(new HourRangeInDay(new TimeValue(8, 30), new TimeValue(12)));
            calendarDateAdd.WorkingHours.Add(new HourRangeInDay(new TimeValue(13, 30), new TimeValue(18)));

            var start = new DateTime(2011, 4, 1, 9, 0, 0);

            calendarDateAdd.Add(start, DurationUtil.Hours(3)).Should().Be(new DateTime(2011, 4, 1, 13, 30, 0));
            calendarDateAdd.Add(start, DurationUtil.Hours(4)).Should().Be(new DateTime(2011, 4, 1, 14, 30, 0));
            calendarDateAdd.Add(start, DurationUtil.Hours(8)).Should().Be(new DateTime(2011, 4, 5, 09, 0, 0));
        }
예제 #8
0
        public void CalendarDateAdd2Test()
        {
            var calendarDateAdd = new CalendarDateAdd();

            //! 주중 8시~12시, 13시~18시가 Working Time 이고, 4월 4일은 제외한다
            //
            calendarDateAdd.AddWorkingWeekDays();
            calendarDateAdd.ExcludePeriods.Add(new DayRange(2011, 4, 4, calendarDateAdd.TimeCalendar));
            calendarDateAdd.WorkingHours.Add(new HourRangeInDay(8, 12));
            calendarDateAdd.WorkingHours.Add(new HourRangeInDay(13, 18));

            DateTime start = new DateTime(2011, 4, 1, 9, 0, 0);

            calendarDateAdd.Add(start, DurationUtil.Hours(3)).Should().Be(calendarDateAdd.Add(start, DurationUtil.Hours(3)));
            calendarDateAdd.Add(start, DurationUtil.Hours(4)).Should().Be(new DateTime(2011, 4, 1, 14, 0, 0));
            calendarDateAdd.Add(start, DurationUtil.Hours(8)).Should().Be(new DateTime(2011, 4, 5, 08, 0, 0));
        }
예제 #9
0
        public void EmptyStartWeekTest()
        {
            var calendarDateAdd = new CalendarDateAdd();

            //! 주중(월~금)만 Working Time으로 넣었습니다.
            calendarDateAdd.AddWorkingWeekDays();

            var start  = new DateTime(2011, 4, 2, 13, 0, 0);
            var offset = DurationUtil.Hours(20); // 20 hours

            // 4월 2일(토), 4월 3일(일) 제외하면... 4월 4일 0시부터 20시간
            calendarDateAdd.Add(start, DurationUtil.Hours(20)).Should().Be(new DateTime(2011, 4, 4, 20, 0, 0));

            // 4월 2일(토), 4월 3일(일) 제외하면... 4월 4일 0시부터 24시간
            calendarDateAdd.Add(start, DurationUtil.Hours(24)).Should().Be(new DateTime(2011, 4, 5, 0, 0, 0));

            // 4월 2일(토), 4월 3일(일) 제외하면... 4월 4일 0시부터 5일이후 이므로 4월9일 (토), 4월 10일(일) 제외하면 4월 11일이 된다.
            calendarDateAdd.Add(start, DurationUtil.Days(5)).Should().Be(new DateTime(2011, 4, 11, 0, 0, 0));
        }
예제 #10
0
        public void IncludeExcludeTest()
        {
            var dateAdd = new DateAdd();

            dateAdd.IncludePeriods.Add(new TimeRange(new DateTime(2011, 3, 17), new DateTime(2011, 4, 20)));

            // setup some periods to exclude
            dateAdd.ExcludePeriods.Add(new TimeRange(new DateTime(2011, 3, 22), new DateTime(2011, 3, 25)));
            dateAdd.ExcludePeriods.Add(new TimeRange(new DateTime(2011, 4, 1), new DateTime(2011, 4, 7)));
            dateAdd.ExcludePeriods.Add(new TimeRange(new DateTime(2011, 4, 15), new DateTime(2011, 4, 16)));

            // positive
            var periodStart = new DateTime(2011, 3, 19);

            dateAdd.Add(periodStart, DurationUtil.Hours(1)).Should().Be(periodStart.AddHours(1));
            dateAdd.Add(periodStart, DurationUtil.Days(4)).Should().Be(new DateTime(2011, 3, 26));
            dateAdd.Add(periodStart, DurationUtil.Days(17)).Should().Be(new DateTime(2011, 4, 14));
            dateAdd.Add(periodStart, DurationUtil.Days(20)).Should().Be(new DateTime(2011, 4, 18));
            dateAdd.Add(periodStart, DurationUtil.Days(20)).Should().Be(new DateTime(2011, 4, 18));

            dateAdd.Add(periodStart, DurationUtil.Days(22), SeekBoundaryMode.Fill).Should().Be(new DateTime(2011, 4, 20));
            dateAdd.Add(periodStart, DurationUtil.Days(22), SeekBoundaryMode.Next).Should().Not.Have.Value();
            dateAdd.Add(periodStart, DurationUtil.Days(22)).Should().Not.Have.Value();


            // negative
            var periodEnd = new DateTime(2011, 4, 18);

            dateAdd.Add(periodEnd, DurationUtil.Hours(-1)).Should().Be(periodEnd.AddHours(-1));
            dateAdd.Add(periodEnd, DurationUtil.Days(-4)).Should().Be(new DateTime(2011, 4, 13));
            dateAdd.Add(periodEnd, DurationUtil.Days(-17)).Should().Be(new DateTime(2011, 3, 22));
            dateAdd.Add(periodEnd, DurationUtil.Days(-20)).Should().Be(new DateTime(2011, 3, 19));
            dateAdd.Add(periodEnd, DurationUtil.Days(-22), SeekBoundaryMode.Fill).Should().Be(new DateTime(2011, 3, 17));
            dateAdd.Add(periodEnd, DurationUtil.Days(-22), SeekBoundaryMode.Next).Should().Not.Have.Value();
            dateAdd.Add(periodEnd, DurationUtil.Days(-22)).Should().Not.Have.Value();
        }
예제 #11
0
        public void IsOverlap_HasRange()
        {
            var users =
                Repository <User> .FindAll(DetachedCriteria.For <User>()
                                           .AddIsOverlap(new TimeRange(DateTime.Now.AddHours(-1), DurationUtil.Hours(2)),
                                                         "ActivePeriod.Start",
                                                         "ActivePeriod.End"));

            Assert.IsTrue(users.Count > 0);
        }
예제 #12
0
        public void DetachedCriteria_AddIsOverlap_IsOverlap_HasRange()
        {
            var loaded =
                Repository <User> .FindAll(DetachedCriteria.For <User>()
                                           .AddIsOverlap(new TimeRange(DateTime.Now.AddHours(-1), DurationUtil.Hours(2)),
                                                         "ActivePeriod.Start",
                                                         "ActivePeriod.End"));


            Assert.IsTrue(loaded.Count > 0);
            loaded.RunEach(log.Debug);
        }