Ejemplo n.º 1
0
            public async Task IsSetToTrueWhenTheUserSelectsAWorkspaceInWhichTheyAreNotAdmins()
            {
                var mockWorkspace = new MockWorkspace {
                    Admin = false
                };
                var interactor = Substitute.For <IInteractor <IObservable <IThreadSafeWorkspace> > >();

                interactor.Execute().Returns(Observable.Return(mockWorkspace));
                InteractorFactory.GetWorkspaceById(Arg.Is(1L)).Returns(interactor);

                View.Select(
                    Arg.Any <string>(),
                    Arg.Any <IEnumerable <SelectOption <IThreadSafeWorkspace> > >(),
                    Arg.Any <int>())
                .Returns(Observable.Return(new MockWorkspace {
                    Id = 1L
                }));
                ViewModel.CanCreatePublicProjects.Subscribe();

                ViewModel.IsPrivate.Accept(false);
                var awaitable = ViewModel.PickWorkspace.ExecuteWithCompletion(Unit.Default);

                TestScheduler.Start();
                await awaitable;

                ViewModel.IsPrivate.Value.Should().BeTrue();
            }
Ejemplo n.º 2
0
            public async Task AreReloadedWhenANewWorkspaceIdIsObserved()
            {
                var initialWorkspaceId       = 10L;
                var newlySelectedWorkspaceId = 11L;
                var observable = TestScheduler.CreateColdObservable(
                    OnNext(0, initialWorkspaceId),
                    OnNext(1, newlySelectedWorkspaceId)
                    );
                var workspace10 = Observable.Return(new MockWorkspace(initialWorkspaceId));
                var workspace11 = Observable.Return(new MockWorkspace(newlySelectedWorkspaceId));

                InteractorFactory.GetWorkspaceById(initialWorkspaceId).Execute().Returns(workspace10);
                InteractorFactory.GetWorkspaceById(newlySelectedWorkspaceId).Execute().Returns(workspace11);
                InteractorFactory.ObserveDefaultWorkspaceId().Execute().Returns(observable);
                TimeService.CurrentDateTime.Returns(DateTimeOffset.Now);
                await ViewModel.Initialize();

                ViewModel.ViewAppeared();
                TestScheduler.AdvanceTo(100);
                TestScheduler.Start();

                InteractorFactory.Received(1).GetProjectSummary(
                    initialWorkspaceId,
                    Arg.Any <DateTimeOffset>(),
                    Arg.Any <DateTimeOffset>());
                InteractorFactory.Received(1).GetProjectSummary(
                    newlySelectedWorkspaceId,
                    Arg.Any <DateTimeOffset>(),
                    Arg.Any <DateTimeOffset>());
            }
            public async Task ReturnsTheWorkspaceWithSmallestIdWhenUsersDefaultWorkspaceIsNotInTheDatabase()
            {
                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 = workspaceId + 3
                };

                DataSource.User.Get().Returns(Observable.Return(user));
                InteractorFactory.GetWorkspaceById(workspaceId + 3)
                .Execute()
                .Returns(Observable.Throw <IThreadSafeWorkspace>(new InvalidOperationException()));
                DataSource.Workspaces.GetAll(Arg.Any <Func <IDatabaseWorkspace, bool> >())
                .Returns(Observable.Return(workspaces));

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

                defaultWorkspace.Id.Should().Be(workspaceId);
            }
            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();

                ViewModel.Tags.Should().HaveCount(4);

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

                ViewModel.Tags[0].Selected.Should().BeTrue();
                ViewModel.Tags[1].Selected.Should().BeTrue();
                ViewModel.Tags[2].Selected.Should().BeFalse();
                ViewModel.Tags[3].Selected.Should().BeFalse();
            }
Ejemplo n.º 5
0
            public async Task IsUpdatedWhenTextIsChanged()
            {
                var workspace      = createWorkspace(13, "Some workspace");
                var oldSuggestions = getTagSuggestions(3, workspace);
                var newSuggestions = getTagSuggestions(1, workspace);
                var oldTagIds      = oldSuggestions.Select(tag => tag.TagId).ToArray();
                var queryText      = "Query text";

                InteractorFactory.GetTagsAutocompleteSuggestions(
                    Arg.Is <IList <string> >(words => words.SequenceEqual(queryText.SplitToQueryWords())))
                .Execute()
                .Returns(Observable.Return(newSuggestions));
                InteractorFactory.GetWorkspaceById(workspace.Id).Execute()
                .Returns(Observable.Return(workspace));
                ViewModel.Prepare((oldTagIds, workspace.Id));
                await ViewModel.Initialize();

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

                ViewModel.Tags.Subscribe(observer);
                ViewModel.FilterText.OnNext(queryText);
                TestScheduler.Start();

                var received = observer.LastEmittedValue();

                received.Should().HaveCount(2);
            }
            public async Task ReturnsNullIfTheWorkspaceIsNotPro(bool billableByDefault)
            {
                const long workspaceId = 11;
                var        workspace   = new MockWorkspace {
                    ProjectsBillableByDefault = billableByDefault
                };
                var feature = new MockWorkspaceFeature {
                    Enabled = false, FeatureId = WorkspaceFeatureId.Pro
                };
                var featureCollection = new MockWorkspaceFeatureCollection {
                    Features = new[] { feature }
                };

                InteractorFactory.GetWorkspaceFeaturesById(workspaceId)
                .Execute()
                .Returns(Observable.Return(featureCollection));
                InteractorFactory.GetWorkspaceById(workspaceId)
                .Execute()
                .Returns(Observable.Return(workspace));

                var projectsAreBillableByDefault =
                    await InteractorFactory.AreProjectsBillableByDefault(workspaceId).Execute();

                projectsAreBillableByDefault.Should().Be(null);
            }
Ejemplo n.º 7
0
            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();

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

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

                observer.LastEmittedValue().Should().HaveCount(5);
                observer.LastEmittedValue().Should()
                .OnlyContain(tag => tag.WorkspaceId == targetWorkspace.Id);
            }
Ejemplo n.º 8
0
            public async Task IsClearedWhenTextIsChanged()
            {
                var workspace            = createWorkspace(13, "Some workspace");
                var oldSuggestions       = getTagSuggestions(3, workspace);
                var newSuggestions       = getTagSuggestions(1, workspace);
                var oldTagIds            = oldSuggestions.Select(tag => tag.TagId).ToArray();
                var autocompleteProvider = Substitute.For <IAutocompleteProvider>();
                var queryText            = "Query text";

                autocompleteProvider
                .Query(Arg.Is <QueryInfo>(
                           arg => arg.SuggestionType == AutocompleteSuggestionType.Tags))
                .Returns(Observable.Return(oldSuggestions));
                autocompleteProvider
                .Query(Arg.Is <QueryInfo>(
                           arg => arg.Text == queryText && arg.SuggestionType == AutocompleteSuggestionType.Tags))
                .Returns(Observable.Return(newSuggestions));
                DataSource.AutocompleteProvider.Returns(autocompleteProvider);
                InteractorFactory.GetWorkspaceById(workspace.Id).Execute()
                .Returns(Observable.Return(workspace));
                ViewModel.Prepare((oldTagIds, workspace.Id));
                await ViewModel.Initialize();

                ViewModel.Text = queryText;

                ViewModel.Tags.Should().HaveCount(1);
            }
Ejemplo n.º 9
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 };

                var autocompleteProvider = Substitute.For <IAutocompleteProvider>();

                autocompleteProvider
                .Query(Arg.Is <QueryInfo>(
                           arg => arg.SuggestionType == AutocompleteSuggestionType.Tags))
                .Returns(Observable.Return(shuffledTags));

                DataSource.AutocompleteProvider.Returns(autocompleteProvider);
                InteractorFactory.GetWorkspaceById(workspace.Id).Execute()
                .Returns(Observable.Return(workspace));

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

                ViewModel.Tags.Should().HaveCount(4);

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

                ViewModel.Tags[0].Selected.Should().BeTrue();
                ViewModel.Tags[1].Selected.Should().BeTrue();
                ViewModel.Tags[2].Selected.Should().BeFalse();
                ViewModel.Tags[3].Selected.Should().BeFalse();
            }
Ejemplo n.º 10
0
            public async Task AddCreationModelWhenNoMatchingSuggestion()
            {
                var workspace      = createWorkspace(13, "Some workspace");
                var tagSuggestions = getTagSuggestions(10, workspace);

                InteractorFactory.GetTagsAutocompleteSuggestions(Arg.Any <IList <string> >())
                .Execute()
                .Returns(Observable.Return(tagSuggestions));
                InteractorFactory.GetWorkspaceById(workspace.Id).Execute()
                .Returns(Observable.Return(workspace));
                var tagIds = tagSuggestions.Select(tag => tag.TagId).ToArray();

                var nonExistingTag = "Non existing tag";

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

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

                ViewModel.Tags.Subscribe(observer);
                ViewModel.FilterText.OnNext(nonExistingTag);
                TestScheduler.Start();

                observer.LastEmittedValue().First().Name.Should().Be(nonExistingTag);
                observer.LastEmittedValue().First().WorkspaceId.Should().Be(workspace.Id);
                observer.LastEmittedValue().First().Selected.Should().BeFalse();
                observer.LastEmittedValue().First().Should().BeOfType <SelectableTagCreationViewModel>();
            }
Ejemplo n.º 11
0
            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)));
                var autocompleteProvider = Substitute.For <IAutocompleteProvider>();

                autocompleteProvider
                .Query(Arg.Is <QueryInfo>(
                           arg => arg.SuggestionType == AutocompleteSuggestionType.Tags))
                .Returns(Observable.Return(tags));
                DataSource.AutocompleteProvider.Returns(autocompleteProvider);
                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.º 12
0
            public TheDoneCommand()
            {
                InteractorFactory
                .AreCustomColorsEnabledForWorkspace(WorkspaceId)
                .Execute()
                .Returns(Observable.Return(false));

                InteractorFactory
                .AreCustomColorsEnabledForWorkspace(proWorkspaceId)
                .Execute()
                .Returns(Observable.Return(true));

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

                InteractorFactory
                .GetWorkspaceById(Arg.Any <long>())
                .Execute()
                .Returns(Observable.Return(Workspace));

                DataSource.Projects
                .Create(Arg.Any <CreateProjectDTO>())
                .Returns(Observable.Return(project));

                project.Id.Returns(projectId);
                Workspace.Id.Returns(proWorkspaceId);
            }
Ejemplo n.º 13
0
            protected void SetupDataSourceToReturnMultipleWorkspaces()
            {
                List <IThreadSafeWorkspace> workspaces = new List <IThreadSafeWorkspace>();
                List <IThreadSafeProject>   projects   = new List <IThreadSafeProject>();

                for (long workspaceId = 0; workspaceId < 2; workspaceId++)
                {
                    var workspace = Substitute.For <IThreadSafeWorkspace>();
                    workspace.Id.Returns(workspaceId);
                    workspace.Name.Returns(Guid.NewGuid().ToString());
                    workspaces.Add(workspace);

                    InteractorFactory
                    .GetWorkspaceById(workspaceId)
                    .Execute()
                    .Returns(Observable.Return(workspace));

                    for (long projectId = 0; projectId < 3; projectId++)
                    {
                        var project = Substitute.For <IThreadSafeProject>();
                        project.Id.Returns(10 * workspaceId + projectId);
                        project.Name.Returns($"Project-{workspaceId}-{projectId}");
                        project.WorkspaceId.Returns(workspaceId);
                        projects.Add(project);
                    }

                    var sameNameProject = Substitute.For <IThreadSafeProject>();
                    sameNameProject.Id.Returns(10 + workspaceId);
                    sameNameProject.Name.Returns("Project");
                    sameNameProject.WorkspaceId.Returns(workspaceId);
                    projects.Add(sameNameProject);
                }

                var defaultWorkspace = workspaces[0];

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

                InteractorFactory
                .AreCustomColorsEnabledForWorkspace(Arg.Any <long>())
                .Execute()
                .Returns(Observable.Return(false));

                DataSource.Projects
                .GetAll(Arg.Any <ProjectPredicate>())
                .Returns(callInfo =>
                         Observable.Return(projects)
                         .Select(p => p.Where <IThreadSafeProject>(callInfo.Arg <ProjectPredicate>())));

                View.Select(
                    Arg.Any <string>(),
                    Arg.Any <IEnumerable <SelectOption <IThreadSafeWorkspace> > >(),
                    Arg.Any <int>())
                .Returns(Observable.Return(new MockWorkspace {
                    Id = 1L
                }));
            }
            public async Task ReturnsTheWorkspaceWithPassedId()
            {
                const long workspaceId = 10;
                var        workspace   = new MockWorkspace();

                DataSource.Workspaces.GetById(workspaceId).Returns(Observable.Return(workspace));

                var returnedWorkspace = await InteractorFactory.GetWorkspaceById(workspaceId).Execute();

                returnedWorkspace.Should().BeSameAs(workspace);
            }
Ejemplo n.º 15
0
            private void setupChangingWorkspaceScenario()
            {
                List <IThreadSafeWorkspace> workspaces = new List <IThreadSafeWorkspace>();
                List <IThreadSafeProject>   projects   = new List <IThreadSafeProject>();

                for (long workspaceId = 0; workspaceId < 2; workspaceId++)
                {
                    var workspace = Substitute.For <IThreadSafeWorkspace>();
                    workspace.Id.Returns(workspaceId);
                    workspace.Name.Returns(Guid.NewGuid().ToString());
                    workspaces.Add(workspace);

                    InteractorFactory
                    .GetWorkspaceById(workspaceId)
                    .Execute()
                    .Returns(Observable.Return(workspace));

                    for (long projectId = 0; projectId < 3; projectId++)
                    {
                        var project = Substitute.For <IThreadSafeProject>();
                        project.Id.Returns(10 * workspaceId + projectId);
                        project.Name.Returns($"Project-{workspaceId}-{projectId}");
                        project.WorkspaceId.Returns(workspaceId);
                        projects.Add(project);
                    }

                    var sameNameProject = Substitute.For <IThreadSafeProject>();
                    sameNameProject.Id.Returns(10 + workspaceId);
                    sameNameProject.Name.Returns("Project");
                    sameNameProject.WorkspaceId.Returns(workspaceId);
                    projects.Add(sameNameProject);
                }

                var defaultWorkspace = workspaces[0];

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

                InteractorFactory
                .AreCustomColorsEnabledForWorkspace(Arg.Any <long>())
                .Execute()
                .Returns(Observable.Return(false));

                DataSource.Projects
                .GetAll(Arg.Any <ProjectPredicate>())
                .Returns(callInfo => Observable.Return(projects)
                         .Select(p => p.Where <IThreadSafeProject>(callInfo.Arg <ProjectPredicate>())));
            }
Ejemplo n.º 16
0
            public ThePickWorkspaceCommand()
            {
                workspace.Id.Returns(workspaceId);
                workspace.Name.Returns(workspaceName);
                defaultWorkspace.Id.Returns(defaultWorkspaceId);

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

                InteractorFactory.GetWorkspaceById(workspaceId).Execute()
                .Returns(Observable.Return(workspace));

                ViewModel.Prepare();
            }
            public async Task IsPopulatedAfterInitialization()
            {
                var workspace      = createWorkspace(13, "Some workspace");
                var tagSuggestions = getTagSuggestions(10, workspace);
                var tagIds         = tagSuggestions.Select(tag => tag.TagId).ToArray();

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

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

                ViewModel.Tags.Should().HaveCount(tagSuggestions.Count());
            }
Ejemplo n.º 18
0
            public ThePickWorkspaceAction()
            {
                workspace.Id.Returns(workspaceId);
                workspace.Name.Returns(workspaceName);
                defaultWorkspace.Id.Returns(defaultWorkspaceId);

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

                InteractorFactory
                .GetWorkspaceById(workspaceId)
                .Execute()
                .Returns(Observable.Return(workspace));

                ViewModel.Initialize("");
            }
Ejemplo n.º 19
0
            public ThePickDefaultWorkspaceMethod()
            {
                defaultWorkspace = new MockWorkspace {
                    Id = defaultWorkspaceId
                };
                workspace = new MockWorkspace {
                    Id = workspaceId, Name = workspaceName
                };

                UserSubject.OnNext(new MockUser());

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

                InteractorFactory.GetWorkspaceById(workspaceId).Execute()
                .Returns(Observable.Return(workspace));

                ViewModel.Prepare();
            }
            public async Task ReturnsUsersDefaultWorkspace()
            {
                const long workspaceId = 11;
                var        workspace   = new MockWorkspace {
                    Id = workspaceId
                };
                var user = new MockUser {
                    DefaultWorkspaceId = workspaceId
                };

                DataSource.User.Get().Returns(Observable.Return(user));
                InteractorFactory.GetWorkspaceById(workspaceId)
                .Execute()
                .Returns(Observable.Return(workspace));

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

                defaultWorkspace.Should().BeEquivalentTo(workspace, options => options.IncludingProperties());
            }
Ejemplo n.º 21
0
            public async Task IsPopulatedAfterInitialization()
            {
                var workspace            = createWorkspace(13, "Some workspace");
                var tagSuggestions       = getTagSuggestions(10, workspace);
                var tagIds               = tagSuggestions.Select(tag => tag.TagId).ToArray();
                var autocompleteProvider = Substitute.For <IAutocompleteProvider>();

                autocompleteProvider
                .Query(Arg.Is <QueryInfo>(
                           arg => arg.SuggestionType == AutocompleteSuggestionType.Tags))
                .Returns(Observable.Return(tagSuggestions));
                DataSource.AutocompleteProvider.Returns(autocompleteProvider);
                InteractorFactory.GetWorkspaceById(workspace.Id).Execute()
                .Returns(Observable.Return(workspace));

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

                ViewModel.Tags.Should().HaveCount(tagSuggestions.Count());
            }
Ejemplo n.º 22
0
            public async Task IsPopulatedAfterInitialization()
            {
                var workspace      = createWorkspace(13, "Some workspace");
                var tagSuggestions = getTagSuggestions(10, workspace);
                var tagIds         = tagSuggestions.Select(tag => tag.TagId).ToArray();

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

                await ViewModel.Initialize(new SelectTagsParameter(tagIds, workspace.Id));

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

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

                observer.LastEmittedValue().Should().HaveCount(tagSuggestions.Count());
            }
            public async Task IsClearedWhenTextIsChanged()
            {
                var workspace      = createWorkspace(13, "Some workspace");
                var oldSuggestions = getTagSuggestions(3, workspace);
                var newSuggestions = getTagSuggestions(1, workspace);
                var oldTagIds      = oldSuggestions.Select(tag => tag.TagId).ToArray();
                var queryText      = "Query text";

                InteractorFactory.GetTagsAutocompleteSuggestions(
                    Arg.Is <IList <string> >(words => words.SequenceEqual(queryText.SplitToQueryWords())))
                .Execute()
                .Returns(Observable.Return(newSuggestions));
                InteractorFactory.GetWorkspaceById(workspace.Id).Execute()
                .Returns(Observable.Return(workspace));
                ViewModel.Prepare((oldTagIds, workspace.Id));
                await ViewModel.Initialize();

                ViewModel.Text = queryText;

                ViewModel.Tags.Should().HaveCount(1);
            }
Ejemplo n.º 24
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));

                await ViewModel.Initialize(new SelectTagsParameter(selectedTagIds, workspace.Id));

                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();
            }