Ejemplo n.º 1
0
            private void prepareWorkspace(bool isProEnabled)
            {
                var workspace = new MockWorkspace {
                    Id = 123
                };
                var workspaceFeatures = new MockWorkspaceFeatureCollection
                {
                    Features = new[] { new MockWorkspaceFeature {
                                           FeatureId = WorkspaceFeatureId.Pro, Enabled = isProEnabled
                                       } }
                };

                var workspaceFeaturesObservable = Observable.Return(workspaceFeatures);
                var workspaceObservable         = Observable.Return(workspace);

                InteractorFactory.GetWorkspaceFeaturesById(workspace.Id)
                .Execute()
                .Returns(workspaceFeaturesObservable);

                View.Select(Arg.Any <string>(), Arg.Any <IEnumerable <SelectOption <IThreadSafeWorkspace> > >(), Arg.Any <int>())
                .Returns(workspaceObservable);
            }
            public async Task ReturnsTheWorkspaceWithSmallestIdWhenUsersDefaultWorkspaceIsNull()
            {
                const long workspaceId = 11;
                var        workspaces  = new[] { new MockWorkspace {
                                                     Id = workspaceId + 2
                                                 }, new MockWorkspace {
                                                     Id = workspaceId
                                                 }, new MockWorkspace {
                                                     Id = workspaceId + 1
                                                 } };
                var user = new MockUser {
                    DefaultWorkspaceId = null
                };

                DataSource.User.Get().Returns(Observable.Return(user));
                DataSource.Workspaces.GetAll(Arg.Any <Func <IDatabaseWorkspace, bool> >())
                .Returns(Observable.Return(workspaces));

                var defaultWorkspace = await InteractorFactory.GetDefaultWorkspace().Execute();

                defaultWorkspace.Id.Should().Be(workspaceId);
            }
Ejemplo n.º 3
0
            public async Task CanBeExecutedForTheSecondTimeIfStartingTheFirstOneFinishesSuccessfully()
            {
                var suggestion       = createSuggestion();
                var timeEntry        = Substitute.For <IThreadSafeTimeEntry>();
                var mockedInteractor = Substitute.For <IInteractor <IObservable <IThreadSafeTimeEntry> > >();

                InteractorFactory.StartSuggestion(Arg.Any <Suggestion>()).Returns(mockedInteractor);
                mockedInteractor.Execute()
                .Returns(Observable.Return(timeEntry));
                await ViewModel.Initialize();

                var auxObservable = TestScheduler.CreateObserver <Unit>();

                Observable.Concat(
                    Observable.Defer(() => ViewModel.StartTimeEntry.Execute(suggestion)),
                    Observable.Defer(() => ViewModel.StartTimeEntry.Execute(suggestion))
                    )
                .Subscribe(auxObservable);
                TestScheduler.Start();

                InteractorFactory.Received(2).StartSuggestion(suggestion);
            }
Ejemplo n.º 4
0
            public async Task ShouldNotTriggerReloadAfterDisappearingAndAppearingImmediately(int numberOfAppearances)
            {
                TimeService.CurrentDateTime.Returns(DateTimeOffset.Now);
                Interactor.Execute()
                .ReturnsForAnyArgs(Observable.Empty <ProjectSummaryReport>(SchedulerProvider.TestScheduler));
                await ViewModel.Initialize();

                ViewModel.CalendarViewModel.ViewAppeared();
                InteractorFactory.ClearReceivedCalls();

                for (int i = 0; i < numberOfAppearances; ++i)
                {
                    ViewModel.ViewDisappeared();
                    ViewModel.ViewAppeared();
                }

                TestScheduler.Start();

                InteractorFactory
                .DidNotReceive()
                .GetProjectSummary(Arg.Any <long>(), Arg.Any <DateTimeOffset>(), Arg.Any <DateTimeOffset>());
            }
            public void PassesTheCurrentWorkspaceToTheViewModel()
            {
                InteractorFactory
                .GetDefaultWorkspace()
                .Execute()
                .Returns(Observable.Return(Workspace));
                Workspace.Id.Returns(DefaultWorkspaceId);
                var viewModel = CreateViewModel();

                viewModel.Initialize("Some name");
                viewModel.AttachView(View);
                TestScheduler.Start();

                viewModel.PickClient.Execute();
                TestScheduler.Start();

                NavigationService.Received()
                .Navigate <SelectClientViewModel, SelectClientParameters, long?>(
                    Arg.Is <SelectClientParameters>(parameter => parameter.WorkspaceId == DefaultWorkspaceId),
                    viewModel.View
                    );
            }
Ejemplo n.º 6
0
            public async Task ShouldTriggerAReportReload()
            {
                TimeService.CurrentDateTime.Returns(DateTimeOffset.Now);
                await ViewModel.Initialize();

                ViewModel.CalendarViewModel.ViewAppeared();
                TestScheduler.Start();

                var mockWorkspace = new MockWorkspace {
                    Id = WorkspaceId + 1
                };

                View.Select(Arg.Any <string>(), Arg.Any <IEnumerable <SelectOption <IThreadSafeWorkspace> > >(), Arg.Any <int>())
                .Returns(Observable.Return(mockWorkspace));

                ViewModel.SelectWorkspace.Execute();
                TestScheduler.Start();

                InteractorFactory.Received().GetProjectSummary(
                    Arg.Is(mockWorkspace.Id),
                    Arg.Any <DateTimeOffset>(),
                    Arg.Any <DateTimeOffset>());
            }
Ejemplo n.º 7
0
        public async Task TracksTheTimeEntryContinuedEvent(ContinueTimeEntryMode continueMode, ContinueTimeEntryOrigin expectedOrigin)
        {
            InteractorFactory
            .ContinueTimeEntry(Arg.Any <ITimeEntryPrototype>(), Arg.Any <ContinueTimeEntryMode>())
            .Execute()
            .Returns(Observable.Return(createdTimeEntry));

            var interactor = new ContinueTimeEntryFromMainLogInteractor(
                InteractorFactory,
                AnalyticsService,
                timeEntryPrototype,
                continueMode,
                IndexInLog,
                DayInLog,
                DaysInPast);

            await interactor.Execute();

            AnalyticsService
            .Received()
            .TimeEntryContinued
            .Track(expectedOrigin, IndexInLog, DayInLog, DaysInPast);
        }
Ejemplo n.º 8
0
            public async Task SetsTheReturnedClientAsTheClientNameProperty()
            {
                const string expectedName = "Some client";
                long?        expectedId   = 10;
                var          client       = Substitute.For <IThreadSafeClient>();

                client.Id.Returns(expectedId.Value);
                client.Name.Returns(expectedName);
                NavigationService
                .Navigate <SelectClientViewModel, SelectClientParameters, long?>(Arg.Any <SelectClientParameters>())
                .Returns(Task.FromResult(expectedId));
                InteractorFactory
                .GetDefaultWorkspace()
                .Execute()
                .Returns(Observable.Return(Workspace));
                DataSource.Clients.GetById(expectedId.Value).Returns(Observable.Return(client));
                Workspace.Id.Returns(WorkspaceId);
                ViewModel.Prepare("Some name");

                await ViewModel.PickClientCommand.ExecuteAsync();

                ViewModel.ClientName.Should().Be(expectedName);
            }
            public async Task MarksTheCalendarAsSelectedIfItIsNotSelected()
            {
                var userCalendars = Enumerable
                                    .Range(0, 9)
                                    .Select(id => new UserCalendar(
                                                id.ToString(),
                                                $"Calendar #{id}",
                                                $"Source #{id % 3}",
                                                false));
                var userCalendarsObservable = Observable.Return(userCalendars);

                InteractorFactory.GetUserCalendars().Execute().Returns(userCalendarsObservable);
                await ViewModel.Initialize();

                var viewModelCalendars = await ViewModel.Calendars.FirstAsync();

                var calendarToBeSelected = viewModelCalendars.First().Items.First();

                ViewModel.SelectCalendar.Execute(calendarToBeSelected);
                TestScheduler.Start();

                calendarToBeSelected.Selected.Should().BeTrue();
            }
            public void EmitsAnEventWhenATimeEntryIsCreated()
            {
                var createSubject = new Subject <IThreadSafeWorkspace>();

                DataSource.Workspaces.Created.Returns(createSubject);
                DataSource.Workspaces.Updated.Returns(Observable.Never <EntityUpdate <IThreadSafeWorkspace> >());
                DataSource.Workspaces.Deleted.Returns(Observable.Never <long>());

                var testScheduler = new TestScheduler();
                var observer      = testScheduler.CreateObserver <IEnumerable <IThreadSafeTimeEntry> >();

                InteractorFactory.ObserveAllTimeEntriesVisibleToTheUser()
                .Execute()
                .Subscribe(observer);

                var mockWorkspace = new MockWorkspace {
                    Id = 42
                };

                createSubject.OnNext(mockWorkspace);

                observer.Messages.Should().HaveCount(1);
            }
        public async Task GetsAnEventWhenAChangeToTimeEntriesHappens()
        {
            var createSubject = new Subject <IThreadSafeTimeEntry>();

            DataSource.TimeEntries.Created.Returns(createSubject.AsObservable());
            DataSource.TimeEntries.Updated.Returns(Observable.Never <EntityUpdate <IThreadSafeTimeEntry> >());
            DataSource.TimeEntries.Deleted.Returns(Observable.Never <long>());

            var testScheduler = new TestScheduler();
            var observer      = testScheduler.CreateObserver <Unit>();

            InteractorFactory.ObserveWorkspaceOrTimeEntriesChanges().Execute()
            .Subscribe(observer);

            var mockTimeEntry = new MockTimeEntry {
                Id = 42
            };

            createSubject.OnNext(mockTimeEntry);
            createSubject.OnNext(mockTimeEntry);

            observer.Messages.Should().HaveCount(2);
        }
Ejemplo n.º 12
0
            public async Task UpdatesTheStoredPreferences()
            {
                var oldBeginningOfWeek = BeginningOfWeek.Tuesday;
                var newBeginningOfWeek = BeginningOfWeek.Sunday;

                var user = Substitute.For <IThreadSafeUser>();

                user.BeginningOfWeek.Returns(oldBeginningOfWeek);
                UserSubject.OnNext(user);
                View.Select(
                    Arg.Any <string>(),
                    Arg.Any <IEnumerable <SelectOption <BeginningOfWeek> > >(),
                    Arg.Any <int>())
                .Returns(Observable.Return(newBeginningOfWeek));

                ViewModel.SelectBeginningOfWeek.Execute();
                TestScheduler.Start();

                await InteractorFactory
                .Received()
                .UpdateUser(Arg.Is <EditUserDTO>(dto => dto.BeginningOfWeek == newBeginningOfWeek))
                .Execute();
            }
Ejemplo n.º 13
0
            public async Task UpdatesTheStoredPreferences()
            {
                var oldDurationFormat = DurationFormat.Decimal;
                var newDurationFormat = DurationFormat.Improved;
                var preferences       = new MockPreferences {
                    DurationFormat = oldDurationFormat
                };

                PreferencesSubject.OnNext(preferences);
                View.Select(
                    Arg.Any <string>(),
                    Arg.Any <IEnumerable <SelectOption <DurationFormat> > >(),
                    Arg.Any <int>())
                .Returns(Observable.Return(newDurationFormat));

                ViewModel.SelectDurationFormat.Execute();
                TestScheduler.Start();

                await InteractorFactory
                .Received()
                .UpdatePreferences(Arg.Is <EditPreferencesDTO>(dto => dto.DurationFormat.Equals(New <DurationFormat> .Value(newDurationFormat))))
                .Execute();
            }
Ejemplo n.º 14
0
            public async Task UpdatesTheStoredPreferences()
            {
                var oldDateFormat = DateFormat.FromLocalizedDateFormat("MM-DD-YYYY");
                var newDateFormat = DateFormat.FromLocalizedDateFormat("DD.MM.YYYY");
                var preferences   = new MockPreferences {
                    DateFormat = oldDateFormat
                };

                PreferencesSubject.OnNext(preferences);
                View.Select(
                    Arg.Any <string>(),
                    Arg.Any <IEnumerable <SelectOption <DateFormat> > >(),
                    Arg.Any <int>())
                .Returns(Observable.Return(newDateFormat));

                ViewModel.SelectDateFormat.Execute();
                TestScheduler.Start();

                await InteractorFactory
                .Received()
                .UpdatePreferences(Arg.Is <EditPreferencesDTO>(dto => dto.DateFormat.Equals(New <DateFormat> .Value(newDateFormat))))
                .Execute();
            }
Ejemplo n.º 15
0
            public void SetsTheEnabledCalendarsWhenThereAreCalendars(NonEmptyString[] nonEmptyStrings)
            {
                if (nonEmptyStrings == null)
                {
                    return;
                }

                InteractorFactory.ClearReceivedCalls();
                var viewModel = CreateViewModel();

                var calendarIds = nonEmptyStrings.Select(str => str.Get).ToArray();

                NavigationService.Navigate <SelectUserCalendarsViewModel, bool, string[]>(Arg.Any <bool>()).Returns(calendarIds);
                PermissionsService.RequestCalendarAuthorization().Returns(Observable.Return(true));
                InteractorFactory.GetUserCalendars().Execute().Returns(
                    Observable.Return(new UserCalendar[] { new UserCalendar() })
                    );

                viewModel.GetStarted.Execute(Unit.Default);
                TestScheduler.Start();

                InteractorFactory.Received().SetEnabledCalendars(calendarIds).Execute();
            }
Ejemplo n.º 16
0
            protected CalendarViewModelTest()
            {
                CalendarInteractor = Substitute.For <IInteractor <IObservable <IEnumerable <CalendarItem> > > >();

                var workspace = new MockWorkspace {
                    Id = DefaultWorkspaceId
                };
                var timeEntry = new MockTimeEntry {
                    Id = TimeEntryId
                };

                TimeService.CurrentDateTime.Returns(Now);

                InteractorFactory
                .GetCalendarItemsForDate(Arg.Any <DateTime>())
                .Returns(CalendarInteractor);

                InteractorFactory
                .GetDefaultWorkspace()
                .Execute()
                .Returns(Observable.Return(workspace));

                InteractorFactory
                .CreateTimeEntry(Arg.Any <ITimeEntryPrototype>(), TimeEntryStartOrigin.CalendarEvent)
                .Execute()
                .Returns(Observable.Return(timeEntry));

                InteractorFactory
                .CreateTimeEntry(Arg.Any <ITimeEntryPrototype>(), TimeEntryStartOrigin.CalendarTapAndDrag)
                .Execute()
                .Returns(Observable.Return(timeEntry));

                InteractorFactory
                .UpdateTimeEntry(Arg.Any <EditTimeEntryDto>())
                .Execute()
                .Returns(Observable.Return(timeEntry));
            }
            public async Task ReturnsSuggestionsFromEventsOneHourInThePastAndOneHourInTheFuture()
            {
                var now = new DateTimeOffset(2020, 1, 2, 3, 4, 5, TimeSpan.Zero);

                TimeService.CurrentDateTime.Returns(now);
                var tenMinutes = TimeSpan.FromMinutes(10);
                var events     = Enumerable.Range(1, 5)
                                 .Select(id => new CalendarItem(
                                             id.ToString(),
                                             CalendarItemSource.Calendar,
                                             now - tenMinutes * id,
                                             tenMinutes,
                                             id.ToString(),
                                             CalendarIconKind.None));

                CalendarService
                .GetEventsInRange(Arg.Any <DateTimeOffset>(), Arg.Any <DateTimeOffset>())
                .Returns(Observable.Return(events));

                var userCalendar = new UserCalendar(
                    "",
                    "",
                    "",
                    true);

                InteractorFactory.GetUserCalendars().Execute()
                .Returns(Observable.Return(new List <UserCalendar> {
                    userCalendar
                }));

                var suggestions = await Provider.GetSuggestions().ToList();

                await CalendarService.Received().GetEventsInRange(now.AddHours(-1), now.AddHours(1));

                suggestions.Should().HaveCount(1)
                .And.OnlyContain(suggestion => events.Any(@event => @event.Description == suggestion.Description));
            }
Ejemplo n.º 18
0
            public async Task IsSortedBySelectedStatusThenByName()
            {
                var workspace      = createWorkspace(13, "Some workspace");
                var tagSuggestions = getTagSuggestions(4, workspace).ToArray();

                var shuffledTags   = new[] { tagSuggestions[3], tagSuggestions[1], tagSuggestions[2], tagSuggestions[0] };
                var selectedTagIds = new[] { tagSuggestions[0].TagId, tagSuggestions[2].TagId };

                InteractorFactory.GetTagsAutocompleteSuggestions(Arg.Any <IList <string> >())
                .Execute()
                .Returns(Observable.Return(shuffledTags));
                InteractorFactory.GetWorkspaceById(workspace.Id).Execute()
                .Returns(Observable.Return(workspace));

                ViewModel.Prepare((selectedTagIds, workspace.Id));
                await ViewModel.Initialize();

                var observer = TestScheduler.CreateObserver <IEnumerable <SelectableTagBaseViewModel> >();

                ViewModel.Tags.Subscribe(observer);
                TestScheduler.Start();

                var tags = observer.LastEmittedValue().ToArray();

                tags.Should().HaveCount(4);


                tags[0].Name.Should().Be("Tag0");
                tags[1].Name.Should().Be("Tag2");
                tags[2].Name.Should().Be("Tag1");
                tags[3].Name.Should().Be("Tag3");

                tags[0].Selected.Should().BeTrue();
                tags[1].Selected.Should().BeTrue();
                tags[2].Selected.Should().BeFalse();
                tags[3].Selected.Should().BeFalse();
            }
            public void SetsProperCalendarsAsSelected(
                NonEmptySet <NonEmptyString> strings0,
                NonEmptySet <NonEmptyString> strings1)
            {
                var enabledCalendarIds   = strings0.Get.Select(str => str.Get).ToList();
                var unenabledCalendarIds = strings1.Get.Select(str => str.Get).ToList();
                var allCalendarIds       = enabledCalendarIds.Concat(unenabledCalendarIds).ToList();

                UserPreferences.EnabledCalendarIds().Returns(enabledCalendarIds);
                var userCalendars = allCalendarIds
                                    .Select(id => new UserCalendar(
                                                id,
                                                "Does not matter",
                                                "Does not matter, pt.2"
                                                ));

                InteractorFactory
                .GetUserCalendars()
                .Execute()
                .Returns(Observable.Return(userCalendars));
                var viewModel = CreateViewModel();

                viewModel.Initialize(false).Wait();

                var calendars = viewModel.Calendars.FirstAsync().Wait();

                foreach (var calendarGroup in calendars)
                {
                    foreach (var calendar in calendarGroup.Items)
                    {
                        if (enabledCalendarIds.Contains(calendar.Id))
                        {
                            calendar.Selected.Should().BeTrue();
                        }
                    }
                }
            }
            public async Task SavesThePreviouslySelectedCalendarIds()
            {
                var initialSelectedIds = new List <string> {
                    "0", "1", "2", "3"
                };

                UserPreferences.EnabledCalendarIds().Returns(initialSelectedIds);
                PermissionsService.CalendarPermissionGranted.Returns(Observable.Return(true));

                var userCalendars = Enumerable
                                    .Range(0, 9)
                                    .Select(id => new UserCalendar(
                                                id.ToString(),
                                                $"Calendar #{id}",
                                                $"Source #{id % 3}",
                                                false));

                InteractorFactory
                .GetUserCalendars()
                .Execute()
                .Returns(Observable.Return(userCalendars));
                await ViewModel.Initialize();

                var selectedIds = new[] { "0", "2", "4", "7" };

                var calendars = userCalendars
                                .Where(calendar => selectedIds.Contains(calendar.Id))
                                .Select(calendar => new SelectableUserCalendarViewModel(calendar, false));

                ViewModel.SelectCalendar.ExecuteSequentally(calendars)
                .PrependAction(ViewModel.Close)
                .Subscribe();

                TestScheduler.Start();

                UserPreferences.Received().SetEnabledCalendars(initialSelectedIds.ToArray());
            }
            public async Task ReloadsSuggestionsWhenTimeEntriesUpdate()
            {
                var changesSubject = new Subject <Unit>();

                InteractorFactory.ObserveWorkspaceOrTimeEntriesChanges().Execute().Returns(changesSubject);

                var provider = suggestionProvider();

                SetProviders(SuggestionProviderContainer, provider);
                var observer = TestScheduler.CreateObserver <Suggestion[]>();

                await ViewModel.Initialize();

                ViewModel.Suggestions.Subscribe(observer);

                changesSubject.OnNext(Unit.Default);

                TestScheduler.Start();

                observer.Messages.Should().HaveCount(2);
                observer.Messages.First().Value.Value.Should().HaveCount(0);
                observer.LastEmittedValue().Should().HaveCount(0);
                await provider.Received(2).GetSuggestions();
            }
Ejemplo n.º 22
0
            public void IsSetToTheFirstEligibleForProjectCreationIfDefaultIsNotEligible()
            {
                var observer         = TestScheduler.CreateObserver <string>();
                var defaultWorkspace = Substitute.For <IThreadSafeWorkspace>();

                defaultWorkspace.Name.Returns(DefaultWorkspaceName);
                defaultWorkspace.Admin.Returns(false);
                defaultWorkspace.OnlyAdminsMayCreateProjects.Returns(true);
                var eligibleWorkspace = Substitute.For <IThreadSafeWorkspace>();

                eligibleWorkspace.Name.Returns("Eligible workspace for project creation");
                eligibleWorkspace.Admin.Returns(true);
                InteractorFactory.GetDefaultWorkspace().Execute()
                .Returns(Observable.Return(defaultWorkspace));
                InteractorFactory.GetAllWorkspaces().Execute()
                .Returns(Observable.Return(new[] { defaultWorkspace, eligibleWorkspace }));

                var viewModel = CreateViewModel();

                viewModel.WorkspaceName.Subscribe(observer);
                TestScheduler.Start();

                observer.LastEmittedValue().Should().Be(eligibleWorkspace.Name);
            }
Ejemplo n.º 23
0
        public void PropagatesErrorIfUpdateFails()
        {
            var failingTimeEntry = Models.TimeEntry.Builder.Create(12)
                                   .SetStart(now)
                                   .SetSyncStatus(SyncStatus.InSync)
                                   .SetDescription("")
                                   .SetUserId(11)
                                   .SetWorkspaceId(10)
                                   .SetAt(now)
                                   .Build();

            var timeEntryObservable = Observable.Return(failingTimeEntry);
            var errorObservable     = Observable.Throw <IThreadSafeTimeEntry>(new DatabaseOperationException <IDatabaseTimeEntry>(new Exception()));

            InteractorFactory.GetTimeEntryById(Arg.Is(timeEntry.Id))
            .Execute()
            .Returns(timeEntryObservable);
            DataSource.TimeEntries.Update(Arg.Any <IThreadSafeTimeEntry>()).Returns(errorObservable);
            var observer = Substitute.For <IObserver <Unit> >();

            interactor.Execute().Subscribe(observer);

            observer.Received().OnError(Arg.Any <DatabaseOperationException <IDatabaseTimeEntry> >());
        }
                public void EmitsFalseAfterAllTheCalendarsHaveBeenDeselected()
                {
                    var observer = Substitute.For <IObserver <bool> >();

                    ViewModel.Done.Enabled.Subscribe(observer);

                    var userCalendars = Enumerable
                                        .Range(0, 3)
                                        .Select(id => new UserCalendar(id.ToString(), id.ToString(), "Doesn't matter"));

                    var selectedableUserCalendars = userCalendars
                                                    .Select(userCalendar => new SelectableUserCalendarViewModel(userCalendar, false));

                    InteractorFactory
                    .GetUserCalendars()
                    .Execute()
                    .Returns(Observable.Return(userCalendars));


                    var auxObserver = TestScheduler.CreateObserver <Unit>();

                    ViewModel.SelectCalendar.ExecuteSequentally(
                        selectedableUserCalendars
                        .Concat(selectedableUserCalendars)
                        )
                    .Subscribe(auxObserver);

                    TestScheduler.Start();

                    Received.InOrder(() =>
                    {
                        observer.OnNext(false);
                        observer.OnNext(true);
                        observer.OnNext(false);
                    });
                }
            public async Task ClosesTheViewModelAndReturnsTheInitialCalendarIds()
            {
                var initialSelectedIds = new List <string> {
                    "0", "1", "2", "3"
                };

                UserPreferences.EnabledCalendarIds().Returns(initialSelectedIds);

                var userCalendars = Enumerable
                                    .Range(0, 9)
                                    .Select(id => new UserCalendar(
                                                id.ToString(),
                                                $"Calendar #{id}",
                                                $"Source #{id % 3}",
                                                false));

                InteractorFactory
                .GetUserCalendars()
                .Execute()
                .Returns(Observable.Return(userCalendars));
                await ViewModel.Initialize();

                var selectedIds = new[] { "0", "2", "4", "7" };

                var calendars = userCalendars
                                .Where(calendar => selectedIds.Contains(calendar.Id))
                                .Select(calendar => new SelectableUserCalendarViewModel(calendar, false));

                ViewModel.SelectCalendar.ExecuteSequentally(calendars)
                .PrependAction(ViewModel.Close)
                .Subscribe();

                TestScheduler.Start();

                await NavigationService.Received().Close(ViewModel, Arg.Is <string[]>(ids => ids.SequenceEqual(initialSelectedIds)));
            }
            public async Task OnlyContainsTagsFromTheSameWorkspaceAsTimeEntry()
            {
                var tags       = new List <TagSuggestion>();
                var workspaces = Enumerable.Range(0, 5)
                                 .Select(i => createWorkspace(i, $"Workspace{i}")).ToArray();

                workspaces.ForEach(workspace
                                   => tags.AddRange(getTagSuggestions(5, workspace)));
                InteractorFactory.GetTagsAutocompleteSuggestions(Arg.Any <IList <string> >())
                .Execute()
                .Returns(Observable.Return(tags));
                var targetWorkspace = workspaces[1];

                InteractorFactory.GetWorkspaceById(targetWorkspace.Id).Execute()
                .Returns(Observable.Return(targetWorkspace));
                var tagIds = tags.Select(tag => tag.TagId).ToArray();

                ViewModel.Prepare((tagIds, targetWorkspace.Id));
                await ViewModel.Initialize();

                ViewModel.Tags.Should().HaveCount(5);
                ViewModel.Tags.Should()
                .OnlyContain(tag => tag.Workspace == targetWorkspace.Name);
            }
Ejemplo n.º 27
0
            public async Task DoesNotIncludeProjectCreationRowWhenTheTextIsEmpty()
            {
                var workspaceId = 0;

                setupWorkspace(workspaceId, isEligibleForProjectCreation: true);
                var projectSuggestions    = getProjectSuggestions(10, workspaceId: workspaceId);
                var suggestionsObservable = Observable.Return(projectSuggestions);

                InteractorFactory
                .GetProjectsAutocompleteSuggestions(Arg.Any <IList <string> >())
                .Execute()
                .Returns(suggestionsObservable);
                var observer = TestScheduler.CreateObserver <IEnumerable <SectionModel <string, AutocompleteSuggestion> > >();

                ViewModel.Suggestions.Subscribe(observer);

                await ViewModel.Initialize();

                TestScheduler.Start();

                var latestSuggestions = observer.Messages.Last().Value.Value;

                latestSuggestions.Should().HaveCount(1);
            }
Ejemplo n.º 28
0
            public async Task GroupsProjectsByWorkspace()
            {
                var suggestions  = new List <ProjectSuggestion>();
                var workspaceIds = new[] { 0, 1, 10, 54 };

                suggestions.AddRange(getProjectSuggestions(3, workspaceId: workspaceIds[0]));
                suggestions.AddRange(getProjectSuggestions(4, workspaceId: workspaceIds[1]));
                suggestions.AddRange(getProjectSuggestions(1, workspaceId: workspaceIds[2]));
                suggestions.AddRange(getProjectSuggestions(10, workspaceId: workspaceIds[3]));
                var suggestionsObservable = Observable.Return(suggestions);

                InteractorFactory
                .GetProjectsAutocompleteSuggestions(Arg.Any <IList <string> >())
                .Execute()
                .Returns(suggestionsObservable);
                var observer = TestScheduler.CreateObserver <IEnumerable <SectionModel <string, AutocompleteSuggestion> > >();

                ViewModel.Suggestions.Subscribe(observer);

                await ViewModel.Initialize();

                TestScheduler.Start();

                var latestSuggestions = observer.Messages.Last().Value.Value.ToArray();

                latestSuggestions.Should().HaveCount(4);

                for (int i = 0; i < latestSuggestions.Length; i++)
                {
                    foreach (var suggestion in latestSuggestions[i].Items)
                    {
                        suggestion.WorkspaceName.Should().Be(latestSuggestions[i].Header);
                        suggestion.WorkspaceId.Should().Be(workspaceIds[i]);
                    }
                }
            }
Ejemplo n.º 29
0
            public async Task UpdatesTheCollapseTimeEntriesProperty()
            {
                var oldValue       = false;
                var newValue       = true;
                var oldPreferences = new MockPreferences {
                    CollapseTimeEntries = oldValue
                };
                var newPreferences = new MockPreferences {
                    CollapseTimeEntries = newValue
                };

                PreferencesSubject.OnNext(oldPreferences);
                InteractorFactory.UpdatePreferences(Arg.Any <EditPreferencesDTO>())
                .Execute()
                .Returns(Observable.Return(newPreferences));

                ViewModel.ToggleTimeEntriesGrouping.Execute();
                TestScheduler.Start();

                await InteractorFactory
                .Received()
                .UpdatePreferences(Arg.Is <EditPreferencesDTO>(dto => dto.CollapseTimeEntries.ValueOr(oldValue) == newValue))
                .Execute();
            }
Ejemplo n.º 30
0
            public void PicksADefaultColorIfTheSelectedColorIsCustomAndTheWorkspaceIsNotPro()
            {
                var someColor = new Color(23, 45, 125);

                NavigationService
                .Navigate <SelectColorViewModel, ColorParameters, Color>(Arg.Any <ColorParameters>(), ViewModel.View)
                .Returns(Task.FromResult(someColor));
                View.Select(
                    Arg.Any <string>(),
                    Arg.Any <IEnumerable <SelectOption <IThreadSafeWorkspace> > >(),
                    Arg.Any <int>())
                .Returns(Observable.Return(new MockWorkspace {
                    Id = workspaceId
                }));
                InteractorFactory.AreCustomColorsEnabledForWorkspace(workspaceId).Execute()
                .Returns(Observable.Return(false));
                ViewModel.PickColor.Execute();
                TestScheduler.Start();

                ViewModel.PickWorkspace.Execute();
                TestScheduler.Start();

                ViewModel.Color.Should().NotBe(someColor);
            }