예제 #1
0
        public void ShowingCloneDialogWhenLoggedInShowsCloneDialog()
        {
            var provider   = Substitutes.GetFullyMockedServiceProvider();
            var hosts      = provider.GetRepositoryHosts();
            var factory    = SetupFactory(provider);
            var connection = provider.GetConnection();

            connection.Login().Returns(Observable.Return(connection));
            var cm = provider.GetConnectionManager();

            cm.Connections.Returns(new ObservableCollection <IConnection> {
                connection
            });
            var host = hosts.GitHubHost;

            hosts.LookupHost(connection.HostAddress).Returns(host);
            host.IsLoggedIn.Returns(true);

            using (var uiController = new UIController((IUIProvider)provider, hosts, factory, cm, LazySubstitute.For <ITwoFactorChallengeHandler>()))
            {
                var list = new List <IView>();
                uiController.SelectFlow(UIControllerFlow.Clone)
                .Subscribe(uc => list.Add(uc as IView),
                           () =>
                {
                    Assert.Equal(1, list.Count);
                    Assert.IsAssignableFrom <IViewFor <IRepositoryCloneViewModel> >(list[0]);
                });
                uiController.Start(connection);
            }
        }
예제 #2
0
        public void FlowWithConnection()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollectionEx <IConnection>();

            cm.Connections.Returns(cons);
            var connection = SetupConnection(provider);

            // simulate being logged in
            cons.Add(connection);

            using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
            {
                var count = 0;
                var flow  = uiController.Configure(UIControllerFlow.Publish, connection);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IRepositoryPublishViewModel> >(uc);
                        ((IGitHubServiceProvider)provider).Received().AddService(uiController, connection);
                        TriggerDone(data.View.ViewModel);
                        break;
                    }
                });

                uiController.Start();
                Assert.Equal(1, count);
                Assert.True(uiController.IsStopped);
            }
        }
예제 #3
0
        public void ShowingCloneDialogWithoutBeingLoggedInShowsLoginDialog()
        {
            var provider  = Substitutes.GetFullyMockedServiceProvider();
            var hosts     = provider.GetRepositoryHosts();
            var factory   = SetupFactory(provider);
            var loginView = factory.GetView(GitHub.Exports.UIViewType.Login);

            loginView.Value.Cancel.Returns(Observable.Empty <object>());
            var cm = provider.GetConnectionManager();

            cm.Connections.Returns(new ObservableCollection <IConnection>());

            using (var uiController = new UIController((IUIProvider)provider, hosts, factory, cm, LazySubstitute.For <ITwoFactorChallengeHandler>()))
            {
                var list = new List <IView>();
                uiController.SelectFlow(UIControllerFlow.Clone)
                .Subscribe(uc => list.Add(uc as IView),
                           () =>
                {
                    Assert.True(list.Count > 1);
                    Assert.IsAssignableFrom <IViewFor <ILoginControlViewModel> >(list[0]);
                });

                uiController.Start(null);
            }
        }
예제 #4
0
        public void Flow()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var hosts    = provider.GetRepositoryHosts();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollection <IConnection>();

            cm.Connections.Returns(cons);

            // simulate being logged in
            cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));

            using (var uiController = new UIController((IUIProvider)provider, hosts, factory, cm))
            {
                var count = 0;
                var flow  = uiController.SelectFlow(UIControllerFlow.Create);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IRepositoryCreationViewModel> >(uc);
                        TriggerDone(uc);
                        break;
                    }
                });

                uiController.Start(null);
                Assert.Equal(1, count);
                Assert.True(uiController.IsStopped);
            }
        }
예제 #5
0
        public void RunningAuthFlowWithoutBeingLoggedInRunsAuthFlow()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var hosts    = provider.GetRepositoryHosts();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollection <IConnection>();

            cm.Connections.Returns(cons);

            using (var uiController = new UIController((IUIProvider)provider, hosts, factory, cm))
            {
                var count = 0;
                var flow  = uiController.SelectFlow(UIControllerFlow.Authentication);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <ILoginControlViewModel> >(uc);
                        TriggerCancel(uc);
                        break;
                    }
                });

                uiController.Start(null);
                Assert.Equal(1, count);
                Assert.True(uiController.IsStopped);
            }
        }
예제 #6
0
        public void RunningNonAuthFlowWhenLoggedInRunsNonAuthFlow()

        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollectionEx <IConnection>();

            cm.Connections.Returns(cons);
            cm.GetLoadedConnections().Returns(cons);

            // simulate being logged in
            cons.Add(SetupConnection(provider));

            using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
            {
                var count = 0;
                var flow  = uiController.Configure(UIControllerFlow.Clone);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IRepositoryCloneViewModel> >(uc);
                        TriggerCancel(data.View.ViewModel);
                        break;
                    }
                });

                uiController.Start();
                Assert.Equal(1, count);
                Assert.True(uiController.IsStopped);
            }
        }
예제 #7
0
    public GitHubPaneViewModelTests()
    {
        var teamExplorerServiceHolder = Substitute.For <ITeamExplorerServiceHolder>();
        var activeRepo = Substitute.For <ILocalRepositoryModel>();

        activeRepo.CloneUrl.Returns(new UriString("https://github.com/foo/foo"));
        teamExplorerServiceHolder
        .When(x => x.Subscribe(Arg.Any <object>(), Arg.Any <Action <ILocalRepositoryModel> >()))
        .Do(x =>
        {
            var invokeAction = x.Arg <Action <ILocalRepositoryModel> >();
            invokeAction(activeRepo);
        });

        var connectionManager     = Substitutes.ConnectionManager;
        var connection            = Substitutes.Connection;
        var connectionHostAddress = HostAddress.Create(activeRepo.CloneUrl.ToString());

        connection.HostAddress.Returns(connectionHostAddress);
        connectionManager.Connections.Returns(new ObservableCollectionEx <IConnection>(new[] {
            connection
        }));
        connection.IsLoggedIn.Returns(true);

        serviceProvider    = Substitutes.GetFullyMockedServiceProvider();
        menuCommandService = new FakeMenuCommandService();
        serviceProvider.GetService(typeof(IMenuCommandService)).Returns(menuCommandService);

        var uiProvider = serviceProvider as IGitHubServiceProvider;

        uiProvider.TryGetService(typeof(IGitHubServiceProvider)).Returns(serviceProvider);

        uiController = Substitute.For <IUIController>();
        uiController.CurrentFlow.Returns(UIControllerFlow.PullRequestList);
        uiController.SelectedFlow.Returns(UIControllerFlow.PullRequestList);
        //uiController
        //    .When(x => x.LoadView(Arg.Any<ViewWithData>()))
        //    .Do(x => lastUiControllerJump = x.Arg<ViewWithData>().ViewType);

        //var exportFactoryProvider = Substitutes.ExportFactoryProvider;
        //uiProvider.TryGetService(typeof(IExportFactoryProvider)).Returns(exportFactoryProvider);
        //exportFactoryProvider.UIControllerFactory.Returns(new ExportFactory<IUIController>(
        //    () => Tuple.Create<IUIController, Action>(uiController, () => { })));

        //viewModel = new GitHubPaneViewModel(
        //    Substitute.For<ISimpleApiClientFactory>(),
        //    teamExplorerServiceHolder,
        //    connectionManager,
        //    repositoryHosts,
        //    Substitute.For<INotificationDispatcher>());

        //viewModel.ActiveRepo = activeRepo;
    }
예제 #8
0
        public void ShowsGistDialog()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollectionEx <IConnection>();

            cm.Connections.Returns(cons);
            cm.GetLoadedConnections().Returns(cons);

            // simulate being logged in
            cons.Add(SetupConnection(provider, true));

            using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
            {
                var  count   = 0;
                bool?success = null;
                var  flow    = uiController.Configure(UIControllerFlow.Gist);
                uiController.ListenToCompletionState()
                .Subscribe(s =>
                {
                    success = s;
                    Assert.Equal(1, count);
                    count++;
                });

                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IGistCreationViewModel> >(uc);
                        TriggerDone(data.View.ViewModel);
                        break;

                    default:
                        Assert.True(false, "Received more views than expected");
                        break;
                    }
                }, () =>
                {
                    Assert.Equal(2, count);
                    count++;
                });

                uiController.Start();
                Assert.Equal(3, count);
                Assert.True(uiController.IsStopped);
                Assert.True(success.HasValue);
                Assert.True(success);
            }
        }
예제 #9
0
    public void ListenToCompletionDoesNotThrowInRelease()
    {
        var provider = Substitutes.GetFullyMockedServiceProvider();

        using (var p = new GitHubServiceProvider(provider))
        {
#if DEBUG
            Assert.ThrowsAny<InvalidOperationException>(() =>
            {
#endif
                p.ListenToCompletionState();
#if DEBUG
            });
#endif
        }
    }
예제 #10
0
        public void AuthFlowWith2FA()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var hosts    = provider.GetRepositoryHosts();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollection <IConnection>();

            cm.Connections.Returns(cons);

            using (var uiController = new UIController((IUIProvider)provider, hosts, factory, cm))
            {
                var count = 0;
                var flow  = uiController.SelectFlow(UIControllerFlow.Clone);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <ILoginControlViewModel> >(uc);
                        var vm = factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.TwoFactor).ViewModel;
                        vm.IsShowing.Returns(true);
                        RaisePropertyChange(vm, "IsShowing");
                        break;

                    case 2:
                        Assert.IsAssignableFrom <IViewFor <ITwoFactorDialogViewModel> >(uc);
                        // login
                        cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
                        // continue by triggering done on login view
                        var v = factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.Login).View;
                        TriggerDone(v);
                        break;

                    case 3:
                        Assert.IsAssignableFrom <IViewFor <IRepositoryCloneViewModel> >(uc);
                        TriggerCancel(uc);
                        break;
                    }
                });

                uiController.Start(null);
                Assert.Equal(3, count);
                Assert.True(uiController.IsStopped);
            }
        }
예제 #11
0
        public void AuthFlowWithout2FA()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var hosts    = provider.GetRepositoryHosts();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollection <IConnection>();

            cm.Connections.Returns(cons);

            using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
            {
                var count = 0;
                var flow  = uiController.Configure(UIControllerFlow.Clone);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <ILoginControlViewModel> >(uc);
                        // login
                        cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
                        TriggerDone(data.View.ViewModel);
                        break;

                    case 2:
                        Assert.IsAssignableFrom <IViewFor <IRepositoryCloneViewModel> >(uc);
                        TriggerCancel(data.View.ViewModel);
                        break;
                    }
                });

                uiController.Start();
                Assert.Equal(2, count);
                Assert.True(uiController.IsStopped);
            }
        }
예제 #12
0
        public void ShuttingDown()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var hosts    = provider.GetRepositoryHosts();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollection <IConnection>();

            cm.Connections.Returns(cons);

            // simulate being logged in
            cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));

            using (var uiController = new UIController((IUIProvider)provider, hosts, factory, cm))
            {
                var  count   = 0;
                bool?success = null;
                var  flow    = uiController.SelectFlow(UIControllerFlow.PullRequests);
                uiController.ListenToCompletionState()
                .Subscribe(s =>
                {
                    success = s;
                    Assert.Equal(4, count);
                    count++;
                });
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IPullRequestListViewModel> >(uc);
                        ((ReplaySubject <ViewWithData>)((IHasDetailView)uc).Open).OnNext(
                            new ViewWithData {
                            Flow = UIControllerFlow.PullRequests, ViewType = GitHub.Exports.UIViewType.PRDetail, Data = 1
                        });
                        break;

                    case 2:
                        Assert.IsAssignableFrom <IViewFor <IPullRequestDetailViewModel> >(uc);
                        TriggerDone(uc);
                        break;

                    case 3:
                        Assert.IsAssignableFrom <IViewFor <IPullRequestListViewModel> >(uc);
                        ((ReplaySubject <ViewWithData>)((IHasDetailView)uc).Open).OnNext(
                            new ViewWithData {
                            Flow = UIControllerFlow.PullRequests, ViewType = GitHub.Exports.UIViewType.PRDetail, Data = 1
                        });
                        break;

                    case 4:
                        Assert.IsAssignableFrom <IViewFor <IPullRequestDetailViewModel> >(uc);
                        uiController.Stop();
                        break;
                    }
                }, () =>
                {
                    Assert.Equal(5, count);
                    count++;
                });

                uiController.Start(null);
                Assert.Equal(6, count);
                Assert.True(uiController.IsStopped);
                Assert.True(success.HasValue);
                Assert.True(success);
            }
        }
예제 #13
0
        public void BackAndForth()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollectionEx <IConnection>();

            cm.Connections.Returns(cons);
            cm.GetLoadedConnections().Returns(cons);

            using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
            {
                var count = 0;
                var flow  = uiController.Configure(UIControllerFlow.Clone);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1: {
                        Assert.IsAssignableFrom <IViewFor <ILoginControlViewModel> >(uc);
                        var vm = (IDialogViewModel)factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.TwoFactor).ViewModel;
                        vm.IsShowing.Returns(true);
                        RaisePropertyChange(vm, "IsShowing");
                        break;
                    }

                    case 2: {
                        Assert.IsAssignableFrom <IViewFor <ITwoFactorDialogViewModel> >(uc);
                        var vm = (IDialogViewModel)factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.TwoFactor).ViewModel;
                        vm.IsShowing.Returns(false);
                        RaisePropertyChange(vm, "IsShowing");
                        TriggerCancel(data.View.ViewModel);
                        break;
                    }

                    case 3: {
                        Assert.IsAssignableFrom <IViewFor <ILoginControlViewModel> >(uc);
                        var vm = (IDialogViewModel)factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.TwoFactor).ViewModel;
                        vm.IsShowing.Returns(true);
                        RaisePropertyChange(vm, "IsShowing");
                        break;
                    }

                    case 4: {
                        Assert.IsAssignableFrom <IViewFor <ITwoFactorDialogViewModel> >(uc);
                        // login
                        cons.Add(SetupConnection(provider));
                        var vm2 = factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.Login).ViewModel;
                        TriggerDone(vm2);
                        break;
                    }

                    case 5: {
                        Assert.IsAssignableFrom <IViewFor <IRepositoryCloneViewModel> >(uc);
                        uiController.Stop();
                        break;
                    }
                    }
                });

                uiController.Start();
                Assert.Equal(5, count);
                Assert.True(uiController.IsStopped);
            }
        }
예제 #14
0
        public void ShowingGistDialogWhenGistNotSupportedShowsLogoutDialog()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var hosts    = provider.GetRepositoryHosts();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollection <IConnection>();

            cm.Connections.Returns(cons);

            var host = hosts.GitHubHost;

            // simulate being logged in
            cons.Add(SetupConnection(provider, hosts, host, true, false));

            using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
            {
                var  count   = 0;
                bool?success = null;
                var  flow    = uiController.Configure(UIControllerFlow.Gist);
                uiController.ListenToCompletionState()
                .Subscribe(s =>
                {
                    success = s;
                    Assert.Equal(3, count);
                    count++;
                });

                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <ILogoutRequiredViewModel> >(uc);
                        host.IsLoggedIn.Returns(false);
                        TriggerDone(uc);
                        break;

                    case 2:
                        Assert.IsAssignableFrom <IViewFor <ILoginControlViewModel> >(uc);
                        // login
                        host.IsLoggedIn.Returns(true);
                        host.SupportsGist.Returns(true);
                        TriggerDone(uc);
                        break;

                    case 3:
                        Assert.IsAssignableFrom <IViewFor <IGistCreationViewModel> >(uc);
                        TriggerDone(uc);
                        break;

                    default:
                        Assert.True(false, "Received more views than expected");
                        break;
                    }
                }, () =>
                {
                    Assert.Equal(4, count);
                    count++;
                });

                uiController.Start();
                Assert.Equal(5, count);
                Assert.True(uiController.IsStopped);
                Assert.True(success.HasValue);
                Assert.True(success);
            }
        }