public async Task GetSessionReturnsSameSessionEachTime()
            {
                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber);
                var result1  = await target.GetSession(newModel);

                var result2 = await target.GetSession(newModel);

                Assert.Same(result1, result2);
            }
            public async Task SessionCanBeCollected()
            {
                WeakReference <IPullRequestSession> weakSession = null;

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                Func <Task> run = async() =>
                {
                    var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber);
                    var session  = await target.GetSession(newModel);

                    Assert.NotNull(session);

                    weakSession = new WeakReference <IPullRequestSession>(session);
                };

                await run();

                GC.Collect();

                IPullRequestSession result;

                weakSession.TryGetTarget(out result);

                Assert.Null(result);
            }
            public async Task GetSessionReturnsSameSessionEachTime()
            {
                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    CreateTeamExplorerContext(CreateRepositoryModel()));

                var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber);
                var result1  = await target.GetSession(newModel);

                var result2 = await target.GetSession(newModel);

                Assert.That(result1, Is.SameAs(result2));
            }
            public async Task GetSessionReturnsAndUpdatesCurrentSessionIfNumbersMatch()
            {
                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                var newModel = CreatePullRequestModel(CurrentBranchPullRequestNumber);
                var result   = await target.GetSession(newModel);

                Assert.Same(target.CurrentSession, result);
                Assert.Same(target.CurrentSession.PullRequest, newModel);
            }
            public async Task GetSessionReturnsNewSessionForPullRequestWithDifferentBaseOwner()
            {
                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                var newModel = CreatePullRequestModel(CurrentBranchPullRequestNumber, "https://github.com/fork/repo");
                var result   = await target.GetSession(newModel);

                Assert.NotSame(target.CurrentSession, result);
                Assert.Same(result.PullRequest, newModel);
                Assert.False(result.IsCheckedOut);
            }
            public async Task GetSessionReturnsAndUpdatesCurrentSessionIfNumbersMatch()
            {
                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    CreateTeamExplorerContext(CreateRepositoryModel()));

                var newModel = CreatePullRequestModel(CurrentBranchPullRequestNumber);
                var result   = await target.GetSession(newModel);

                Assert.That(target.CurrentSession, Is.SameAs(result));
                Assert.That(result.PullRequest, Is.SameAs(newModel));
            }
Exemplo n.º 7
0
            public async Task GetSessionReturnsNewSessionForPullRequestWithDifferentNumber()
            {
                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber);
                var result   = await target.GetSession(newModel);

                Assert.NotSame(target.CurrentSession, result);
                Assert.Same(result.PullRequest, newModel);
                Assert.False(result.IsCheckedOut);
            }
            public async Task GetSessionReturnsNewSessionForPullRequestWithDifferentBaseOwner()
            {
                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    Substitute.For <IPullRequestSessionService>(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    CreateTeamExplorerContext(CreateRepositoryModel()));

                var newModel = CreatePullRequestModel(CurrentBranchPullRequestNumber, "https://github.com/fork/repo");
                var result   = await target.GetSession(newModel);

                Assert.That(target.CurrentSession, Is.Not.SameAs(result));
                Assert.That(result.PullRequest, Is.SameAs(newModel));
                Assert.That(result.IsCheckedOut, Is.False);
            }
            public async Task GetSessionUpdatesCurrentSessionIfCurrentBranchIsPullRequestButWasNotMarked()
            {
                var service = CreatePullRequestService();

                service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty <Tuple <string, int> >());

                var target = new PullRequestSessionManager(
                    service,
                    Substitute.For <IPullRequestSessionService>(),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                Assert.Null(target.CurrentSession);

                var model = CreatePullRequestModel(CurrentBranchPullRequestNumber);

                service.EnsureLocalBranchesAreMarkedAsPullRequests(Arg.Any <ILocalRepositoryModel>(), model).Returns(Observable.Return(true));
                service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(Tuple.Create("owner", CurrentBranchPullRequestNumber)));

                var session = await target.GetSession(model);

                Assert.Same(session, target.CurrentSession);
            }