public void SetsTheStartTimeToCurrentTimeIfParameterDoesNotHaveStartTime(DateTimeOffset now)
            {
                var start     = now.AddHours(-2);
                var parameter = DurationParameter.WithStartAndDuration(start, null);

                TimeService.CurrentDateTime.Returns(now);
                var observer = TestScheduler.CreateObserver <DateTimeOffset>();

                ViewModel.StartTime.Subscribe(observer);

                ViewModel.Initialize(new EditDurationParameters(parameter));

                TestScheduler.Start();
                observer.LastEmittedValue().Should().BeSameDateAs(start);
            }
Beispiel #2
0
            public void WhenChangedWhileUpdatingTheRunningTimeEntryTriggersTheUpdateOfTheStartTime(DateTimeOffset now)
            {
                var start     = now.AddHours(-2);
                var parameter = DurationParameter.WithStartAndDuration(start, null);

                TimeService.CurrentDateTime.Returns(now);

                ViewModel.Prepare(new EditDurationParameters(parameter));

                ViewModel.Duration = TimeSpan.FromHours(4);

                var expectedStart = start.AddHours(-2);

                ViewModel.StartTime.Should().BeSameDateAs(expectedStart);
            }
Beispiel #3
0
            public void UnsubscribesFromTheTheRunningTimeEntryObservable()
            {
                var now = new DateTimeOffset(2018, 02, 20, 0, 0, 0, TimeSpan.Zero);
                var runningTEParameter = DurationParameter.WithStartAndDuration(parameter.Start, null);
                var subject            = new BehaviorSubject <DateTimeOffset>(now);
                var observable         = subject.AsObservable().Publish();

                ViewModel.Prepare(new EditDurationParameters(runningTEParameter));
                TimeService.CurrentDateTime.Returns(now);
                TimeService.CurrentDateTimeObservable.Returns(observable);

                ViewModel.EditStopTimeCommand.Execute();
                subject.OnNext(now.AddSeconds(1));

                ViewModel.StopTime.Should().Be(now);
            }
Beispiel #4
0
            public void IsUpdatedAccordingToTimeServiceForRunningTimeEntries(DateTimeOffset now)
            {
                var start          = now.AddHours(-2);
                var parameter      = DurationParameter.WithStartAndDuration(start, null);
                var tickSubject    = new Subject <DateTimeOffset>();
                var tickObservable = tickSubject.AsObservable().Publish();

                tickObservable.Connect();
                TimeService.CurrentDateTimeObservable.Returns(tickObservable);
                TimeService.CurrentDateTime.Returns(now);
                ViewModel.Prepare(new EditDurationParameters(parameter));

                tickSubject.OnNext(now.AddHours(2));

                ViewModel.Duration.Hours.Should().Be(4);
            }
            public void SetsTheStopTimeToTheValueReturnedByTheSelectDateTimeDialogViewModelWhenEditingACompletedTimeEntry(DateTimeOffset now)
            {
                var start             = now.AddHours(-4);
                var duration          = TimeSpan.FromHours(1);
                var parameterToReturn = DurationParameter.WithStartAndDuration(start, duration);

                NavigationService
                .Navigate <EditDurationViewModel, DurationParameter, DurationParameter>(Arg.Any <DurationParameter>())
                .Returns(parameterToReturn);
                ConfigureEditedTimeEntry(now);
                ViewModel.Prepare(Id);

                ViewModel.EditDurationCommand.ExecuteAsync().Wait();

                ViewModel.Duration.Should().Be(parameterToReturn.Duration.Value);
            }
Beispiel #6
0
            public void ReturnsAValueThatReflectsTheChangesToDurationForRunningTimeEntries(DateTimeOffset start, DateTimeOffset now)
            {
                if (start > now)
                {
                    return;
                }
                TimeService.CurrentDateTime.Returns(now);
                ViewModel.Prepare(DurationParameter.WithStartAndDuration(start, null));
                ViewModel.Duration = TimeSpan.FromMinutes(10);

                ViewModel.SaveCommand.ExecuteAsync().Wait();

                NavigationService.Received().Close(Arg.Is(ViewModel), Arg.Is <DurationParameter>(
                                                       p => p.Start == ViewModel.StartTime && p.Duration == null
                                                       )).Wait();
            }
            public void WhenChangedWhileUpdatingFinishedTimeEntryTriggersTheUpdateOfTheStopTime(DateTimeOffset now)
            {
                var start     = now.AddHours(-2);
                var parameter = DurationParameter.WithStartAndDuration(start, now - start);

                TimeService.CurrentDateTime.Returns(now);
                ViewModel.Prepare(new EditDurationParameters(parameter));
                var observer = TestScheduler.CreateObserver <DateTimeOffset>();

                ViewModel.StopTime.Subscribe(observer);

                ViewModel.ChangeDuration.Execute(TimeSpan.FromHours(4));

                TestScheduler.Start();
                var expectedStop = now.AddHours(2);

                observer.LastValue().Should().BeSameDateAs(expectedStop);
            }
Beispiel #8
0
            public void IsUpdatedAccordingToTimeServiceForRunningTimeEntries(DateTimeOffset now, byte hours)
            {
                var duration       = TimeSpan.FromHours(hours);
                var parameter      = DurationParameter.WithStartAndDuration(now, null);
                var tickSubject    = new Subject <DateTimeOffset>();
                var tickObservable = tickSubject.AsObservable().Publish();

                tickObservable.Connect();
                TimeService.CurrentDateTimeObservable.Returns(tickObservable);
                TimeService.CurrentDateTime.Returns(now);
                ViewModel.Prepare(new EditDurationParameters(parameter));

                var newCurrentTime = now + duration;

                tickSubject.OnNext(newCurrentTime);

                ViewModel.Duration.Should().Be(duration);
            }
Beispiel #9
0
            public async Task SetsTheIsEditingDurationDateToTrueWhileTheViewDoesNotReturnAndThenSetsItBackToFalse()
            {
                var now = DateTimeOffset.UtcNow;
                var parameterToReturn = DurationParameter.WithStartAndStop(now.AddHours(-2), null);
                var tcs = new TaskCompletionSource <DurationParameter>();

                NavigationService
                .Navigate <DurationParameter, DurationParameter>(typeof(EditDurationViewModel), Arg.Any <DurationParameter>())
                .Returns(tcs.Task);
                ViewModel.Prepare(now);

                var toWait = ViewModel.ChangeDurationCommand.ExecuteAsync();

                ViewModel.IsEditingDuration.Should().BeTrue();
                tcs.SetResult(parameterToReturn);
                await toWait;

                ViewModel.IsEditingDuration.Should().BeFalse();
            }
            public void StopsARunningTimeEntry()
            {
                var now = new DateTimeOffset(2018, 02, 20, 0, 0, 0, TimeSpan.Zero);
                var runningTEParameter = DurationParameter.WithStartAndDuration(parameter.Start, null);

                ViewModel.Initialize(new EditDurationParameters(runningTEParameter));
                TimeService.CurrentDateTime.Returns(now);
                var stopObserver      = TestScheduler.CreateObserver <DateTimeOffset>();
                var isRunningObserver = TestScheduler.CreateObserver <bool>();

                ViewModel.StopTime.Subscribe(stopObserver);
                ViewModel.IsRunning.Subscribe(isRunningObserver);

                ViewModel.StopTimeEntry.Execute();

                TestScheduler.Start();
                isRunningObserver.LastEmittedValue().Should().BeFalse();
                stopObserver.LastEmittedValue().Should().Be(now);
            }
            public void IsUpdatedAccordingToTimeServiceForRunningTimeEntries(DateTimeOffset now)
            {
                var start          = now.AddHours(-2);
                var parameter      = DurationParameter.WithStartAndDuration(start, null);
                var tickSubject    = new Subject <DateTimeOffset>();
                var tickObservable = tickSubject.AsObservable().Publish();
                var observer       = TestScheduler.CreateObserver <TimeSpan>();

                ViewModel.Duration.Subscribe(observer);
                tickObservable.Connect();
                TimeService.CurrentDateTimeObservable.Returns(tickObservable);
                TimeService.CurrentDateTime.Returns(now);
                ViewModel.Initialize(new EditDurationParameters(parameter));

                tickSubject.OnNext(now.AddHours(2));

                TestScheduler.Start();
                observer.LastEmittedValue().Hours.Should().Be(4);
            }
            public void UnsubscribesFromTheTheRunningTimeEntryObservable()
            {
                var now = new DateTimeOffset(2018, 02, 20, 0, 0, 0, TimeSpan.Zero);
                var runningTEParameter = DurationParameter.WithStartAndDuration(parameter.Start, null);
                var subject            = new BehaviorSubject <DateTimeOffset>(now);
                var observable         = subject.AsObservable().Publish();
                var stopObserver       = TestScheduler.CreateObserver <DateTimeOffset>();

                ViewModel.StopTime.Subscribe(stopObserver);
                ViewModel.Initialize(new EditDurationParameters(runningTEParameter));
                TimeService.CurrentDateTime.Returns(now);
                TimeService.CurrentDateTimeObservable.Returns(observable);

                ViewModel.StopTimeEntry.Execute();
                subject.OnNext(now.AddSeconds(1));

                TestScheduler.Start();
                stopObserver.LastEmittedValue().Should().Be(now);
            }
            public async Task CorrespondsToSettings(BeginningOfWeek beginningOfWeek)
            {
                System.Diagnostics.Debug.WriteLine(beginningOfWeek);
                var now       = new DateTimeOffset(2019, 1, 1, 10, 12, 14, TimeSpan.Zero);
                var start     = now.AddHours(-2);
                var parameter = DurationParameter.WithStartAndDuration(start, null);

                TimeService.CurrentDateTime.Returns(now);
                var user = Substitute.For <IThreadSafeUser>();

                user.BeginningOfWeek.Returns(beginningOfWeek);
                user.Id.Returns(123456);
                DataSource.User.Current.Returns(Observable.Return(user));
                var viewModel = CreateViewModel();

                await viewModel.Initialize(new EditDurationParameters(parameter));

                TestScheduler.Start();
                viewModel.BeginningOfWeek.Should().Be(beginningOfWeek);
            }
            public void ReturnsAValueThatReflectsTheChangesToDurationForRunningTimeEntries(DateTimeOffset start, DateTimeOffset now)
            {
                if (start > now)
                {
                    return;
                }
                TimeService.CurrentDateTime.Returns(now);
                var startObserver = TestScheduler.CreateObserver <DateTimeOffset>();

                ViewModel.StartTime.Subscribe(startObserver);

                ViewModel.Prepare(new EditDurationParameters(DurationParameter.WithStartAndDuration(start, null)));
                ViewModel.ChangeDuration.Execute(TimeSpan.FromMinutes(10));

                ViewModel.Save.Execute();

                TestScheduler.Start();
                NavigationService.Received().Close(Arg.Is(ViewModel), Arg.Is <DurationParameter>(
                                                       p => p.Start == startObserver.LastValue() && p.Duration == null
                                                       )).Wait();
            }
Beispiel #15
0
        private async Task editTimes(EditViewTapSource tapSource)
        {
            analyticsService.EditViewTapped.Track(tapSource);

            var isDurationInitiallyFocused = tapSource == EditViewTapSource.Duration;

            var duration = await durationSubject.FirstAsync();

            var startTime         = startTimeSubject.Value;
            var currentDuration   = DurationParameter.WithStartAndDuration(startTime, duration);
            var editDurationParam = new EditDurationParameters(currentDuration, false, isDurationInitiallyFocused);

            var selectedDuration = await Navigate <EditDurationViewModel, EditDurationParameters, DurationParameter>(editDurationParam)
                                   .ConfigureAwait(false);

            startTimeSubject.OnNext(selectedDuration.Start);
            if (selectedDuration.Duration.HasValue)
            {
                durationSubject.OnNext(selectedDuration.Duration);
            }
        }
            public void IsUpdatedAccordingToTimeServiceForRunningTimeEntries(DateTimeOffset now, byte hours)
            {
                var duration       = TimeSpan.FromHours(hours);
                var parameter      = DurationParameter.WithStartAndDuration(now, null);
                var tickSubject    = new Subject <DateTimeOffset>();
                var tickObservable = tickSubject.AsObservable().Publish();

                tickObservable.Connect();
                TimeService.CurrentDateTimeObservable.Returns(tickObservable);
                TimeService.CurrentDateTime.Returns(now);
                var durationObserver = TestScheduler.CreateObserver <TimeSpan>();

                ViewModel.Duration.Subscribe(durationObserver);

                ViewModel.Initialize(new EditDurationParameters(parameter));

                var newCurrentTime = now + duration;

                tickSubject.OnNext(newCurrentTime);

                TestScheduler.Start();
                durationObserver.LastEmittedValue().Should().Be(duration);
            }
            public void ReturnsAValueThatReflectsTheChangesToDurationForRunningTimeEntries(DateTimeOffset start, DateTimeOffset now)
            {
                if (start > now)
                {
                    return;
                }
                TimeService.CurrentDateTime.Returns(now);
                var startObserver = TestScheduler.CreateObserver <DateTimeOffset>();
                var viewModel     = CreateViewModel();

                viewModel.AttachView(View);
                viewModel.StartTime.Subscribe(startObserver);

                viewModel.Initialize(new EditDurationParameters(DurationParameter.WithStartAndDuration(start, null)));
                viewModel.ChangeDuration.Execute(TimeSpan.FromMinutes(10));

                viewModel.Save.Execute();

                TestScheduler.Start();
                var result = viewModel.Result.GetAwaiter().GetResult();

                result.Start.Should().Be(startObserver.LastEmittedValue());
                result.Duration.Should().BeNull();
            }
Beispiel #18
0
            public void ReturnsAValueThatReflectsTheChangesToDurationForFinishedTimeEntries(DateTimeOffset start, DateTimeOffset stop)
            {
                if (start >= stop)
                {
                    return;
                }

                var now = DateTimeOffset.UtcNow;

                TimeService.CurrentDateTime.Returns(now);
                if (start >= now)
                {
                    return;
                }

                ViewModel.Prepare(new EditDurationParameters(DurationParameter.WithStartAndDuration(start, stop - start)));
                ViewModel.Duration = TimeSpan.FromMinutes(10);

                ViewModel.SaveCommand.ExecuteAsync().Wait();

                NavigationService.Received().Close(Arg.Is(ViewModel), Arg.Is <DurationParameter>(
                                                       p => p.Start == ViewModel.StartTime && p.Duration == ViewModel.Duration
                                                       )).Wait();
            }
Beispiel #19
0
 public EditDurationParameters(DurationParameter durationParam,
                               bool isDurationInitiallyFocused = false)
 {
     DurationParam = durationParam;
     IsDurationInitiallyFocused = isDurationInitiallyFocused;
 }