Inheritance: MonthTimeRange
コード例 #1
0
        public void GetNextMonthTest()
        {
            var month = new MonthRange();

            month.GetNextMonth().Should().Be(month.AddMonths(1));
            month.GetNextMonth().Start.Should().Be(ClockProxy.Clock.Now.AddMonths(1).StartTimeOfMonth());
        }
コード例 #2
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
        public void YearMonthTest() {
            var currentYear = ClockProxy.Clock.Now.Year;
            var calendar = TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero);

            var january = new MonthRange(currentYear, TimeSpec.CalendarYearStartMonth, calendar);

            january.Month.Should().Be(TimeSpec.CalendarYearStartMonth);
            january.Start.Should().Be(new DateTime(currentYear, 1, 1));
            january.End.Should().Be(new DateTime(currentYear, 2, 1));
        }
コード例 #3
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
        public void InitValuesTest() {
            var now = ClockProxy.Clock.Now;
            var firstMonth = new DateTime(now.Year, now.Month, 1);
            var secondMonth = firstMonth.AddMonths(1);

            var month = new MonthRange(now.Year, now.Month, TimeCalendar.NewEmptyOffset());

            month.Start.Should().Be(firstMonth);
            month.End.Should().Be(secondMonth);
        }
コード例 #4
0
        public void InitValuesTest()
        {
            var now         = ClockProxy.Clock.Now;
            var firstMonth  = new DateTime(now.Year, now.Month, 1);
            var secondMonth = firstMonth.AddMonths(1);

            var month = new MonthRange(now.Year, now.Month, TimeCalendar.NewEmptyOffset());

            month.Start.Should().Be(firstMonth);
            month.End.Should().Be(secondMonth);
        }
コード例 #5
0
        public void YearMonthTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;
            var calendar    = TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero);

            var january = new MonthRange(currentYear, TimeSpec.CalendarYearStartMonth, calendar);

            january.Month.Should().Be(TimeSpec.CalendarYearStartMonth);
            january.Start.Should().Be(new DateTime(currentYear, 1, 1));
            january.End.Should().Be(new DateTime(currentYear, 2, 1));
        }
コード例 #6
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
        public void DefaultCalendarTest() {
            var yearStart = ClockProxy.Clock.Now.TrimToMonth();

            Enumerable
                .Range(0, TimeSpec.MonthsPerYear)
                .RunEach(offset => {
                             var month = new MonthRange(yearStart.AddMonths(offset));

                             month.Year.Should().Be(yearStart.Year);
                             month.Month.Should().Be(offset + 1);
                             month.Start.Should().Be(yearStart.AddMonths(offset).Add(month.TimeCalendar.StartOffset));
                             month.End.Should().Be(yearStart.AddMonths(offset + 1).Add(month.TimeCalendar.EndOffset));
                         });
        }
コード例 #7
0
        public void DefaultCalendarTest()
        {
            var yearStart = ClockProxy.Clock.Now.TrimToMonth();

            Enumerable
            .Range(0, TimeSpec.MonthsPerYear)
            .RunEach(offset => {
                var month = new MonthRange(yearStart.AddMonths(offset));

                month.Year.Should().Be(yearStart.Year);
                month.Month.Should().Be(offset + 1);
                month.Start.Should().Be(yearStart.AddMonths(offset).Add(month.TimeCalendar.StartOffset));
                month.End.Should().Be(yearStart.AddMonths(offset + 1).Add(month.TimeCalendar.EndOffset));
            });
        }
コード例 #8
0
        public void PeriodOutsideTouchingLimitsTest() {
            var limits = new MonthRange(2011, 3); // new TimeRange(new DateTime(2011, 3, 1), new DateTime(2011, 3, 31));
            var gapCalculator = new TimeGapCalculator<TimeRange>();

            var excludePeriods = new TimePeriodCollection
                                 {
                                     new TimeRange(new DateTime(2011, 2, 1), new DateTime(2011, 3, 5)),
                                     new TimeRange(new DateTime(2011, 3, 20), new DateTime(2011, 4, 15))
                                 };

            var gaps = gapCalculator.GetGaps(excludePeriods, limits);

            gaps.Count.Should().Be(1);
            gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 5), new DateTime(2011, 3, 20))).Should().Be.True();
        }
コード例 #9
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
        public void CurrentMonthTest() {
            var now = ClockProxy.Clock.Now;

            CultureTestData.Default
                .RunEach(culture => {
                             var currentYearMonthStart = now.StartTimeOfMonth();
                             var currentYearMonthEnd = currentYearMonthStart.AddMonths(1);

                             var month = new MonthRange(currentYearMonthStart, TimeCalendar.New(culture, TimeSpan.Zero, TimeSpan.Zero));

                             month.Year.Should().Be(now.Year);
                             month.Month.Should().Be(now.Month);
                             month.Start.Should().Be(currentYearMonthStart);
                             month.End.Should().Be(currentYearMonthEnd);
                         });
        }
コード例 #10
0
        public void CurrentMonthTest()
        {
            var now = ClockProxy.Clock.Now;

            CultureTestData.Default
            .RunEach(culture => {
                var currentYearMonthStart = now.StartTimeOfMonth();
                var currentYearMonthEnd   = currentYearMonthStart.AddMonths(1);

                var month = new MonthRange(currentYearMonthStart, TimeCalendar.New(culture, TimeSpan.Zero, TimeSpan.Zero));

                month.Year.Should().Be(now.Year);
                month.Month.Should().Be(now.Month);
                month.Start.Should().Be(currentYearMonthStart);
                month.End.Should().Be(currentYearMonthEnd);
            });
        }
コード例 #11
0
        public void GetDaysTest()
        {
            var month = new MonthRange();
            var days  = month.GetDays().ToList();

            days.Count.Should().Be.GreaterThan(27);

            Enumerable
            .Range(0, days.Count)
            .RunEach(index => {
                var day = days[index];
                day.Start.Should().Be(month.Start.AddDays(index));
                day.End.Should().Be(day.TimeCalendar.MapEnd(day.Start.AddDays(1)));

                day.UnmappedStart.Should().Be(month.Start.AddDays(index));
                day.UnmappedEnd.Should().Be(day.Start.AddDays(1));
            });
        }
コード例 #12
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
        public void MonthMomentTest() {
            var month = new MonthRange(new DateTime(2008, 1, 15), TimeCalendar.NewEmptyOffset());

            month.IsReadOnly.Should().Be.True();
            month.Year.Should().Be(2008);
            month.Month.Should().Be(TimeSpec.CalendarYearStartMonth);
            month.Start.Should().Be(new DateTime(2008, 1, 1));
            month.End.Should().Be(new DateTime(2008, 2, 1));

            var previous = month.GetPreviousMonth();

            previous.Year.Should().Be(2007);
            previous.Month.Should().Be(12);
            previous.Start.Should().Be(new DateTime(2007, 12, 1));
            previous.End.Should().Be(new DateTime(2008, 1, 1));

            var next = month.GetNextMonth();

            next.Year.Should().Be(2008);
            next.Month.Should().Be(2);
            next.Start.Should().Be(new DateTime(2008, 2, 1));
            next.End.Should().Be(new DateTime(2008, 3, 1));
        }
コード例 #13
0
        public void MonthMomentTest()
        {
            var month = new MonthRange(new DateTime(2008, 1, 15), TimeCalendar.NewEmptyOffset());

            month.IsReadOnly.Should().Be.True();
            month.Year.Should().Be(2008);
            month.Month.Should().Be(TimeSpec.CalendarYearStartMonth);
            month.Start.Should().Be(new DateTime(2008, 1, 1));
            month.End.Should().Be(new DateTime(2008, 2, 1));

            var previous = month.GetPreviousMonth();

            previous.Year.Should().Be(2007);
            previous.Month.Should().Be(12);
            previous.Start.Should().Be(new DateTime(2007, 12, 1));
            previous.End.Should().Be(new DateTime(2008, 1, 1));

            var next = month.GetNextMonth();

            next.Year.Should().Be(2008);
            next.Month.Should().Be(2);
            next.Start.Should().Be(new DateTime(2008, 2, 1));
            next.End.Should().Be(new DateTime(2008, 3, 1));
        }
コード例 #14
0
        public void AddMonthsTest()
        {
            var now = ClockProxy.Clock.Now;

            CultureTestData.Default
            .RunEach(culture => {
                var currentYearMonthStart = now.StartTimeOfMonth();
                var currentYearMonthEnd   = currentYearMonthStart.AddMonths(1);

                var currentYearMonth = new MonthRange(currentYearMonthStart, TimeCalendar.NewEmptyOffset(culture));

                currentYearMonth.Start.Should().Be(currentYearMonthStart);
                currentYearMonth.End.Should().Be(currentYearMonthEnd);
                currentYearMonth.AddMonths(0).Should().Be(currentYearMonth);

                var previousYearMonthStart = new DateTime(now.Year - 1, now.Month, 1);
                var previousYearMonthEnd   = previousYearMonthStart.AddMonths(1);
                var previousYearMonth      = currentYearMonth.AddMonths(TimeSpec.MonthsPerYear * -1);

                previousYearMonth.Start.Should().Be(previousYearMonthStart);
                previousYearMonth.End.Should().Be(previousYearMonthEnd);
                previousYearMonth.Month.Should().Be(currentYearMonth.Month);
                previousYearMonth.Start.Year.Should().Be(currentYearMonth.Start.Year - 1);
                previousYearMonth.End.Year.Should().Be(currentYearMonth.End.Year - 1);

                var nextYearMonthStart = now.AddYears(1).StartTimeOfMonth();
                var nextYearMonthEnd   = nextYearMonthStart.AddMonths(1);
                var nextYearMonth      = currentYearMonth.AddMonths(TimeSpec.MonthsPerYear);

                nextYearMonth.Start.Should().Be(nextYearMonthStart);
                nextYearMonth.End.Should().Be(nextYearMonthEnd);
                nextYearMonth.Month.Should().Be(currentYearMonth.Month);
                nextYearMonth.Start.Year.Should().Be(currentYearMonth.Start.Year + 1);
                nextYearMonth.End.Year.Should().Be(currentYearMonth.End.Year + 1);
            });
        }
コード例 #15
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
        public void GetDaysTest() {
            var month = new MonthRange();
            var days = month.GetDays().ToList();

            days.Count.Should().Be.GreaterThan(27);

            Enumerable
                .Range(0, days.Count)
                .RunEach(index => {
                             var day = days[index];
                             day.Start.Should().Be(month.Start.AddDays(index));
                             day.End.Should().Be(day.TimeCalendar.MapEnd(day.Start.AddDays(1)));

                             day.UnmappedStart.Should().Be(month.Start.AddDays(index));
                             day.UnmappedEnd.Should().Be(day.Start.AddDays(1));
                         });
        }
コード例 #16
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
        public void AddMonthsTest() {
            var now = ClockProxy.Clock.Now;

            CultureTestData.Default
                .RunEach(culture => {
                             var currentYearMonthStart = now.StartTimeOfMonth();
                             var currentYearMonthEnd = currentYearMonthStart.AddMonths(1);

                             var currentYearMonth = new MonthRange(currentYearMonthStart, TimeCalendar.NewEmptyOffset(culture));

                             currentYearMonth.Start.Should().Be(currentYearMonthStart);
                             currentYearMonth.End.Should().Be(currentYearMonthEnd);
                             currentYearMonth.AddMonths(0).Should().Be(currentYearMonth);

                             var previousYearMonthStart = new DateTime(now.Year - 1, now.Month, 1);
                             var previousYearMonthEnd = previousYearMonthStart.AddMonths(1);
                             var previousYearMonth = currentYearMonth.AddMonths(TimeSpec.MonthsPerYear * -1);

                             previousYearMonth.Start.Should().Be(previousYearMonthStart);
                             previousYearMonth.End.Should().Be(previousYearMonthEnd);
                             previousYearMonth.Month.Should().Be(currentYearMonth.Month);
                             previousYearMonth.Start.Year.Should().Be(currentYearMonth.Start.Year - 1);
                             previousYearMonth.End.Year.Should().Be(currentYearMonth.End.Year - 1);

                             var nextYearMonthStart = now.AddYears(1).StartTimeOfMonth();
                             var nextYearMonthEnd = nextYearMonthStart.AddMonths(1);
                             var nextYearMonth = currentYearMonth.AddMonths(TimeSpec.MonthsPerYear);

                             nextYearMonth.Start.Should().Be(nextYearMonthStart);
                             nextYearMonth.End.Should().Be(nextYearMonthEnd);
                             nextYearMonth.Month.Should().Be(currentYearMonth.Month);
                             nextYearMonth.Start.Year.Should().Be(currentYearMonth.Start.Year + 1);
                             nextYearMonth.End.Year.Should().Be(currentYearMonth.End.Year + 1);
                         });
        }
コード例 #17
0
ファイル: MonthRangeFixture.cs プロジェクト: debop/NFramework
 public void GetNextMonthTest() {
     var month = new MonthRange();
     month.GetNextMonth().Should().Be(month.AddMonths(1));
     month.GetNextMonth().Start.Should().Be(ClockProxy.Clock.Now.AddMonths(1).StartTimeOfMonth());
 }