Ejemplo n.º 1
0
            public async Task SetToDefaultWorkspaceIfAllWorkspacesAreEligible()
            {
                var defaultWorkspace = Substitute.For <IThreadSafeWorkspace>();

                defaultWorkspace.Name.Returns(DefaultWorkspaceName);
                defaultWorkspace.Admin.Returns(true);

                var eligibleWorkspace = Substitute.For <IThreadSafeWorkspace>();

                eligibleWorkspace.Name.Returns("Eligible workspace for project creation");
                eligibleWorkspace.Admin.Returns(true);

                var eligibleWorkspace2 = Substitute.For <IThreadSafeWorkspace>();

                eligibleWorkspace.Name.Returns("Another Eligible Workspace");
                eligibleWorkspace.Admin.Returns(true);

                InteractorFactory.GetDefaultWorkspace().Execute()
                .Returns(Observable.Return(defaultWorkspace));
                InteractorFactory.GetAllWorkspaces().Execute()
                .Returns(Observable.Return(new[] { eligibleWorkspace2, defaultWorkspace, eligibleWorkspace }));

                await ViewModel.Initialize();

                ViewModel.WorkspaceName.Should().Be(defaultWorkspace.Name);
            }
Ejemplo n.º 2
0
            public void IsSetToTheDefaultWorkspaceIfAllWorkspacesAreEligibleForProjectCreation()
            {
                var observer         = TestScheduler.CreateObserver <string>();
                var defaultWorkspace = Substitute.For <IThreadSafeWorkspace>();

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

                eligibleWorkspace.Name.Returns("Eligible workspace for project creation");
                eligibleWorkspace.Admin.Returns(true);
                var eligibleWorkspace2 = Substitute.For <IThreadSafeWorkspace>();

                eligibleWorkspace.Name.Returns("Another Eligible Workspace");
                eligibleWorkspace.Admin.Returns(true);
                InteractorFactory.GetDefaultWorkspace().Execute()
                .Returns(Observable.Return(defaultWorkspace));
                InteractorFactory.GetAllWorkspaces().Execute()
                .Returns(Observable.Return(new[] { eligibleWorkspace2, defaultWorkspace, eligibleWorkspace }));

                var viewModel = CreateViewModel();

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

                observer.LastEmittedValue().Should().Be(defaultWorkspace.Name);
            }
Ejemplo n.º 3
0
            private IThreadSafeWorkspace setupWorkspace(int id, bool isEligibleForProjectCreation)
            {
                var workspace = new MockWorkspace {
                    Id = id, Name = "ws", Admin = false, OnlyAdminsMayCreateProjects = !isEligibleForProjectCreation
                };

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new[] { workspace }));
                return(workspace);
            }
            public async Task AddsAllWorkspacesToTheListOfSuggestions()
            {
                var workspaces = GenerateWorkspaceList();

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(workspaces));

                await ViewModel.Initialize();

                ViewModel.Suggestions.Should().HaveCount(10);
            }
            public async Task FiltersTheSuggestionsWhenItChanges()
            {
                var workspaces = GenerateWorkspaceList();

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(workspaces));
                await ViewModel.Initialize();

                ViewModel.Text = "0";

                ViewModel.Suggestions.Should().HaveCount(1);
            }
            public async Task AddsEligibleWorkspacesToTheList()
            {
                var workspaces         = GenerateWorkspaceList();
                var eligibleWorkspaces = workspaces.Where(ws => ws.IsEligibleForProjectCreation());

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(workspaces));

                await ViewModel.Initialize();

                ViewModel.Workspaces.Should().HaveCount(eligibleWorkspaces.Count());
            }
            public async Task ReturnsFalseIfNoWorkspaceIsEligible()
            {
                var workspace = new MockWorkspace {
                    Id = 1, Name = "ws", Admin = false, OnlyAdminsMayCreateProjects = true
                };

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new[] { workspace }));

                await ViewModel.Initialize();

                ViewModel.SuggestCreation.Should().BeFalse();
            }
Ejemplo n.º 8
0
            public async Task ReturnsAllWorkspacesInTheDatabase()
            {
                var workspaces =
                    Enumerable.Range(0, 10)
                    .Select(id => new MockWorkspace {
                    Id = id
                });

                DataSource.Workspaces.GetAll().Returns(Observable.Return(workspaces));

                var returnedWorkspaces = await InteractorFactory.GetAllWorkspaces().Execute();

                returnedWorkspaces.Count().Should().Be(workspaces.Count());
            }
            public async Task ResetsNoWorkspaceStateWhenAnotherWorkspaceIsFetched()
            {
                var workspace = Substitute.For <IThreadSafeWorkspace>();

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new List <IThreadSafeWorkspace>()
                {
                    workspace
                }));

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

                AccessRestrictionStorage.Received().SetNoWorkspaceStateReached(Arg.Is(false));
            }
            public async Task ClosesWhenAnotherWorkspaceIsFetched()
            {
                var workspace = Substitute.For <IThreadSafeWorkspace>();

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new List <IThreadSafeWorkspace>()
                {
                    workspace
                }));

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

                View.Received().Close();
            }
            public async Task ReturnsTrueEvenIfAProjectWithSameNameExist()
            {
                var workspace = new MockWorkspace {
                    Id = 1, Name = "ws", Admin = true
                };

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new[] { workspace }));

                await ViewModel.Initialize();

                ViewModel.Text = name;

                ViewModel.SuggestCreation.Should().BeTrue();
            }
            public async Task ReturnsTrueIfTheTextIsValid()
            {
                var workspace = new MockWorkspace {
                    Id = 1, Name = "ws", Admin = true
                };

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new[] { workspace }));

                await ViewModel.Initialize();

                ViewModel.Text = "playing bongo";

                ViewModel.SuggestCreation.Should().BeTrue();
            }
            public async Task ClosesTheViewModelReturningTheCreatedIdIfTheProjectIsCreated()
            {
                var workspace = new MockWorkspace {
                    Id = 1, Name = "ws", Admin = true, OnlyAdminsMayCreateProjects = true
                };

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new[] { workspace }));
                const long projectId = 10;

                setupProjectCreationResult(projectId);
                ViewModel.Prepare(SelectProjectParameter.WithIds(null, null, 10));
                await ViewModel.Initialize();

                ViewModel.Text = "New project name";

                await ViewModel.CreateProjectCommand.ExecuteAsync();

                await NavigationService.Received()
                .Close(ViewModel, Arg.Is <SelectProjectParameter>(p => p.ProjectId == projectId));
            }
Ejemplo n.º 14
0
                public async Task ClosesTheViewModelReturningTheCreatedIdIfTheProjectIsCreated()
                {
                    var workspace = new MockWorkspace {
                        Id = 1, Name = "ws", Admin = true, OnlyAdminsMayCreateProjects = true
                    };

                    InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(new[] { workspace }));
                    const long projectId = 10;

                    setupProjectCreationResult(projectId);
                    ViewModel.Prepare(SelectProjectParameter.WithIds(null, null, 10));
                    await ViewModel.Initialize();

                    var projectName             = "Some Project";
                    var createProjectSuggestion = new CreateEntitySuggestion(Resources.CreateProject, projectName);

                    ViewModel.SelectProject.Execute(createProjectSuggestion);
                    TestScheduler.Start();

                    await NavigationService.Received()
                    .Close(ViewModel, Arg.Is <SelectProjectParameter>(p => p.ProjectId == projectId));
                }
Ejemplo n.º 15
0
            public async Task SetsToTheFirstEligibleProjectIfDefaultIsNotEligible()
            {
                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 }));

                await ViewModel.Initialize();

                ViewModel.WorkspaceName.Should().Be(eligibleWorkspace.Name);
            }
            public ThePrepareMethod()
            {
                var workspaces = GenerateWorkspaceList();

                InteractorFactory.GetAllWorkspaces().Execute().Returns(Observable.Return(workspaces));
            }