public async Task ReturnsSegmentsJustOnceWhenChangingDateRange()
            {
                var segments = new ChartSegment[2] {
                    new ChartSegment("Project 1", "Client 1", 50f, 10, 0, "ff0000"),
                    new ChartSegment("Project 2", "Client 2", 50f, 10, 0, "00ff00")
                };
                var projectsNotSyncedCount = 0;

                var currentDate = new DateTimeOffset(2018, 5, 23, 0, 0, 0, TimeSpan.Zero);
                var start       = new DateTimeOffset(2018, 5, 1, 0, 0, 0, TimeSpan.Zero);
                var end         = new DateTimeOffset(2018, 5, 7, 0, 0, 0, TimeSpan.Zero);

                TimeService.CurrentDateTime.Returns(currentDate);

                var delayed = Observable
                              .Return(new ProjectSummaryReport(segments, projectsNotSyncedCount))
                              .Delay(TimeSpan.FromMilliseconds(100));

                var instant = Observable
                              .Return(new ProjectSummaryReport(segments, projectsNotSyncedCount));

                ReportsProvider.GetProjectSummary(Arg.Any <long>(), Arg.Any <DateTimeOffset>(), Arg.Any <DateTimeOffset>())
                .Returns(delayed, instant);

                await Initialize();

                ViewModel.ChangeDateRangeCommand.Execute(
                    DateRangeParameter.WithDates(start, end));

                await delayed;

                ViewModel.Segments.Count.Should().Be(segments.Length);
            }
        public override DateRangeParameter GetDateRange()
        {
            var now   = TimeService.CurrentDateTime.Date;
            var start = new DateTimeOffset(now.Year, now.Month, 1, 0, 0, 0, TimeSpan.Zero);
            var end   = start.AddMonths(1).AddDays(-1);

            return(DateRangeParameter.WithDates(start, end));
        }
Example #3
0
        public override DateRangeParameter GetDateRange()
        {
            var yesterday = TimeService.CurrentDateTime.Date.AddDays(-1);

            return(DateRangeParameter
                   .WithDates(yesterday, yesterday)
                   .WithSource(ReportsSource.ShortcutYesterday));
        }
Example #4
0
        public override DateRangeParameter GetDateRange()
        {
            var today = TimeService.CurrentDateTime.Date;

            return(DateRangeParameter
                   .WithDates(today, today)
                   .WithSource(ReportsSource.ShortcutToday));
        }
        public override DateRangeParameter GetDateRange()
        {
            var thisYear = TimeService.CurrentDateTime.Year;
            var start    = new DateTimeOffset(thisYear, 1, 1, 0, 0, 0, TimeSpan.Zero);
            var end      = start.AddYears(1).AddDays(-1);

            return(DateRangeParameter.WithDates(start, end));
        }
Example #6
0
        public override DateRangeParameter GetDateRange()
        {
            var now        = TimeService.CurrentDateTime.Date;
            var difference = (now.DayOfWeek - beginningOfWeek.ToDayOfWeekEnum() + 7) % 7;
            var start      = now.AddDays(-(difference + 7));
            var end        = start.AddDays(6);

            return(DateRangeParameter.WithDates(start, end));
        }
Example #7
0
        public override DateRangeParameter GetDateRange()
        {
            var lastMonth = TimeService.CurrentDateTime.Date.AddMonths(-1);
            var start     = new DateTimeOffset(lastMonth.Year, lastMonth.Month, 1, 0, 0, 0, TimeSpan.Zero);
            var end       = start.AddMonths(1).AddDays(-1);

            return(DateRangeParameter
                   .WithDates(start, end)
                   .WithSource(ReportsSource.ShortcutLastMonth));
        }
        private void selectStartOfSelectionIfNeeded()
        {
            if (startOfSelection == null)
            {
                return;
            }

            var date      = startOfSelection.DateTimeOffset;
            var dateRange = DateRangeParameter.WithDates(date, date);

            changeDateRange(dateRange);
        }
            public void ReturnsThisWeekWhenStartAndEndOfCurrentWeekAreSeleted(
                int currentYear, int currentMonth, int currentDay,
                int startYear, int startMonth, int startDay,
                int endYear, int endMonth, int endDay)
            {
                var currentDate = new DateTimeOffset(currentYear, currentMonth, currentDay, 0, 0, 0, TimeSpan.Zero);
                var start       = new DateTimeOffset(startYear, startMonth, startDay, 0, 0, 0, TimeSpan.Zero);
                var end         = new DateTimeOffset(endYear, endMonth, endDay, 0, 0, 0, TimeSpan.Zero);

                TimeService.CurrentDateTime.Returns(currentDate);
                ViewModel.ChangeDateRangeCommand.Execute(
                    DateRangeParameter.WithDates(start, end).WithSource(ReportsSource.Calendar));

                ViewModel.CurrentDateRangeString.Should().Be($"{Resources.ThisWeek} ▾");
            }
        private void calendarDayTapped(CalendarDayViewModel tappedDay)
        {
            if (startOfSelection == null)
            {
                var date = tappedDay.DateTimeOffset;

                var dateRange = DateRangeParameter.WithDates(date, date);
                startOfSelection = tappedDay;
                highlightDateRange(dateRange);
            }
            else
            {
                var startDate = startOfSelection.DateTimeOffset;
                var endDate   = tappedDay.DateTimeOffset;

                var dateRange = DateRangeParameter.WithDates(startDate, endDate);
                startOfSelection = null;
                changeDateRange(dateRange);
            }
        }
Example #11
0
            public async Task ReturnsSelectedDateRangeAsStringIfTheSelectedPeriodIsNotTheCurrentWeek(
                DateTimeOffset start,
                DateTimeOffset end,
                DateFormat dateFormat,
                string expectedResult)
            {
                TimeService.CurrentDateTime.Returns(DateTimeOffset.UtcNow);
                var preferences = Substitute.For <IThreadSafePreferences>();

                preferences.DateFormat.Returns(dateFormat);
                var preferencesSubject = new Subject <IThreadSafePreferences>();

                DataSource.Preferences.Current.Returns(preferencesSubject.AsObservable());
                await ViewModel.Initialize();

                preferencesSubject.OnNext(preferences);

                ViewModel.ChangeDateRangeCommand.Execute(
                    DateRangeParameter.WithDates(start, end).WithSource(ReportsSource.Calendar));

                ViewModel.CurrentDateRangeString.Should().Be(expectedResult);
            }
            public void SelectingAnyDateRangeDoesNotMakeTheAppCrash(DateTimeOffset a, DateTimeOffset b, DateTimeOffset c)
            {
                var dates = new[] { a, b, c };

                Array.Sort(dates);
                var start = dates[0];
                var now   = dates[1];
                var end   = dates[2];

                TimeService.CurrentDateTime.Returns(now);
                var selectedRange  = DateRangeParameter.WithDates(start, end).WithSource(ReportsSource.Calendar);
                var customShortcut = new CustomShortcut(selectedRange, TimeService);

                // in this property test it is not possible to use the default ViewModel,
                // because we have to reset it in each iteration of the test
                var viewModel = CreateViewModel();

                viewModel.Prepare();
                viewModel.Initialize().Wait();

                Action usingShortcut = () => viewModel.QuickSelectCommand.Execute(customShortcut);

                usingShortcut.Should().NotThrow();
            }
Example #13
0
        public override DateRangeParameter GetDateRange()
        {
            var today = TimeService.CurrentDateTime.Date;

            return(DateRangeParameter.WithDates(today, today));
        }