public GitHubPaneViewModelTests()
    {
        var repositoryHosts = Substitutes.RepositoryHosts;
        repositoryHosts.IsLoggedInToAnyHost.Returns(true);

        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 ObservableCollection<IConnection>(new[] {
                connection
            }));
        connection.Login().Returns(Observable.Return(connection));

        var host = Substitute.For<IRepositoryHost>();
        host.IsLoggedIn.Returns(true);
        repositoryHosts.LookupHost(connectionHostAddress).Returns(host);

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

        var uiProvider = serviceProvider as IUIProvider;
        uiProvider.TryGetService(typeof(IUIProvider)).Returns(serviceProvider);

        uiController = Substitute.For<IUIController>();
        uiController.CurrentFlow.Returns(UIControllerFlow.PullRequests);
        uiController.SelectedFlow.Returns(UIControllerFlow.PullRequests);
        uiController
            .When(x => x.Jump(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;
    }
Exemple #2
0
    public GitHubPaneViewModelTests()
    {
        var repositoryHosts = Substitutes.RepositoryHosts;

        repositoryHosts.IsLoggedInToAnyHost.Returns(true);

        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 ObservableCollection <IConnection>(new[] {
            connection
        }));
        connection.Login().Returns(Observable.Return(connection));

        var host = Substitute.For <IRepositoryHost>();

        host.IsLoggedIn.Returns(true);
        repositoryHosts.LookupHost(connectionHostAddress).Returns(host);

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

        var uiProvider = serviceProvider as IUIProvider;

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

        uiController = Substitute.For <IUIController>();
        uiController.CurrentFlow.Returns(UIControllerFlow.PullRequests);
        uiController.SelectedFlow.Returns(UIControllerFlow.PullRequests);
        uiController
        .When(x => x.Jump(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;
    }