Exemplo n.º 1
0
            public void IncreasesTheYearIfMonthIs12(NonNegativeInt nonNegativeInt)
            {
                var year          = nonNegativeInt.Get;
                var calendarMonth = new CalendarMonth(year, 12);

                var nextCalendarMonth = calendarMonth.Next();

                nextCalendarMonth.Year.Should().Be(year + 1);
            }
Exemplo n.º 2
0
            public void SetsTheMonthTo1IfMonthIs12(NonNegativeInt nonNegativeInt)
            {
                var year          = nonNegativeInt.Get;
                var calendarMonth = new CalendarMonth(year, 12);

                var nextCalendarMonth = calendarMonth.Next();

                nextCalendarMonth.Month.Should().Be(1);
            }
Exemplo n.º 3
0
            public void IncrementsTheMonthWhenMonthIsLessThan12(int month)
            {
                if (month == 12)
                {
                    return;
                }
                var calendarMonth = new CalendarMonth(2018, month);

                var nextCalendarMonth = calendarMonth.Next();

                nextCalendarMonth.Month.Should().Be(month + 1);
            }
Exemplo n.º 4
0
            public void DoesNotIncrementTheYearWhenMonthIsLessThan12(int month)
            {
                if (month == 12)
                {
                    return;
                }
                var year          = 2020;
                var calendarMonth = new CalendarMonth(year, month);

                var nextCalendarMonth = calendarMonth.Next();

                nextCalendarMonth.Year.Should().Be(year);
            }
Exemplo n.º 5
0
        public override async Task Initialize()
        {
            await base.Initialize();

            var now = timeService.CurrentDateTime;

            initialMonth = new CalendarMonth(now.Year, now.Month).AddMonths(-(MonthsToShow - 1));

            beginningOfWeekObservable = dataSource.User.Current
                                        .Select(user => user.BeginningOfWeek)
                                        .DistinctUntilChanged();

            DayHeadersObservable = beginningOfWeekObservable.Select(mapDayHeaders);

            ReloadObservable = reloadSubject.AsObservable();

            MonthsObservable = beginningOfWeekObservable.CombineLatest(
                timeService.MidnightObservable.StartWith(timeService.CurrentDateTime),
                (beginningOfWeek, today) =>
            {
                var monthIterator = new CalendarMonth(today.Year, today.Month).AddMonths(-(MonthsToShow - 1));
                var months        = new List <ReportsCalendarPageViewModel>();
                for (int i = 0; i < MonthsToShow; i++, monthIterator = monthIterator.Next())
                {
                    months.Add(new ReportsCalendarPageViewModel(monthIterator, beginningOfWeek, today));
                }
                return(months);
            });

            RowsInCurrentMonthObservable = MonthsObservable.CombineLatest(
                CurrentPageObservable.DistinctUntilChanged(),
                (months, page) => months[page].RowCount)
                                           .Select(CommonFunctions.Identity);

            CurrentMonthObservable = monthSubject
                                     .AsObservable()
                                     .StartWith(MonthsToShow - 1)
                                     .Select(convertPageIndexToCalendarMonth)
                                     .Share();

            QuickSelectShortcutsObservable = beginningOfWeekObservable.Select(createQuickSelectShortcuts);

            beginningOfWeek = (await dataSource.User.Current.FirstAsync()).BeginningOfWeek;

            QuickSelectShortcuts = createQuickSelectShortcuts(beginningOfWeek);

            SelectPeriod(reportPeriod);

            isInitialized    = true;
            viewAppearedOnce = false;
        }
        public override async Task Initialize()
        {
            await base.Initialize();

            var now = timeService.CurrentDateTime;

            initialMonth = new CalendarMonth(now.Year, now.Month).AddMonths(-(MonthsToShow - 1));

            beginningOfWeekObservable = dataSource.User.Current
                                        .Select(user => user.BeginningOfWeek)
                                        .DistinctUntilChanged();

            DayHeadersObservable = beginningOfWeekObservable
                                   .Select(mapDayHeaders)
                                   .AsDriver(new List <string>().AsReadOnly(), schedulerProvider);

            ReloadObservable = reloadSubject.AsObservable();

            MonthsObservable = beginningOfWeekObservable.CombineLatest(
                timeService.MidnightObservable.StartWith(timeService.CurrentDateTime),
                (beginningOfWeek, today) =>
            {
                var monthIterator = new CalendarMonth(today.Year, today.Month).AddMonths(-(MonthsToShow - 1));
                var months        = new List <ReportsCalendarPageViewModel>();
                for (int i = 0; i < MonthsToShow; i++, monthIterator = monthIterator.Next())
                {
                    months.Add(new ReportsCalendarPageViewModel(monthIterator, beginningOfWeek, today));
                }
                return(months.ToImmutableList());
            })
                               .AsDriver(ImmutableList <ReportsCalendarPageViewModel> .Empty, schedulerProvider);

            RowsInCurrentMonthObservable = MonthsObservable.CombineLatest(
                CurrentPageObservable.DistinctUntilChanged(),
                (months, page) => months[page].RowCount)
                                           .Select(CommonFunctions.Identity)
                                           .AsDriver(0, schedulerProvider);

            CurrentMonthObservable = monthSubject
                                     .AsObservable()
                                     .StartWith(MonthsToShow - 1)
                                     .Select(convertPageIndexToCalendarMonth)
                                     .Share()
                                     .AsDriver(default, schedulerProvider);
            public async Task InitializesTheMonthsPropertyToLast12Months()
            {
                var now = new DateTimeOffset(2020, 4, 2, 1, 1, 1, TimeSpan.Zero);

                TimeService.CurrentDateTime.Returns(now);
                ViewModel.Prepare();

                await ViewModel.Initialize();

                ViewModel.Months.Should().HaveCount(12);
                var firstDateTime = now.AddMonths(-11);
                var month         = new CalendarMonth(
                    firstDateTime.Year, firstDateTime.Month);

                for (int i = 0; i < 12; i++, month = month.Next())
                {
                    ViewModel.Months[i].CalendarMonth.Should().Be(month);
                }
            }
Exemplo n.º 8
0
            public async Task InitializesTheMonthsPropertyToTheMonthsToShow()
            {
                var observer = TestScheduler.CreateObserver <List <ReportsCalendarPageViewModel> >();
                var now      = new DateTimeOffset(2020, 4, 2, 1, 1, 1, TimeSpan.Zero);

                TimeService.CurrentDateTime.Returns(now);
                ViewModel.Prepare();

                await ViewModel.Initialize();

                ViewModel.MonthsObservable
                .Subscribe(observer);

                TestScheduler.Start();
                var months = observer.Values().First();

                months.Should().HaveCount(ReportsCalendarViewModel.MonthsToShow);
                var firstDateTime = now.AddMonths(-(ReportsCalendarViewModel.MonthsToShow - 1));
                var month         = new CalendarMonth(
                    firstDateTime.Year, firstDateTime.Month);

                for (int i = 0; i < (ReportsCalendarViewModel.MonthsToShow - 1); i++, month = month.Next())
                {
                    months[i].CalendarMonth.Should().Be(month);
                }
            }