Esempio n. 1
0
        public void TestEnsureActivePrsArePresent_ReturnsAllActivePrsMatchingRepoFilter()
        {
            var systemUnderTest = new TfProject(new TeamProject(), _tfsConnection, _logger);
            var includedRepo    = Substitute.For <ITfGitRepository>();
            var excludedRepo    = Substitute.For <ITfGitRepository>();
            var repoFilter      = Substitute.For <IRepositoryFilter>();

            repoFilter.IncludesRepo(includedRepo).Returns(true);
            repoFilter.IncludesRepo(excludedRepo).Returns(false);
            systemUnderTest.RepositoryFilter = repoFilter;
            var activePrs     = new List <IPullRequest>();
            var expectedPrIds = new List <int>();

            for (int i = 0; i < 6; i++)
            {
                var pr = Substitute.For <IPullRequest>();
                pr.Id.Returns(i);
                activePrs.Add(pr);
                if (i % 2 == 0)
                {
                    pr.Repository.Returns(includedRepo);
                    expectedPrIds.Add(i);
                }
                else
                {
                    pr.Repository.Returns(excludedRepo);
                }
            }

            var actualPrIds = systemUnderTest.EnsureActivePrsArePresent(activePrs);

            Assert.That(actualPrIds, Is.EquivalentTo(expectedPrIds));
        }
Esempio n. 2
0
        public void TestEnsureActivePrsArePresent_ReplacesUnapprovedPullRequestWithMoreRecentlyRetrievedInstance()
        {
            const int testKey                = 5678;
            var       systemUnderTest        = new TfProject(new TeamProject(), _tfsConnection, _logger);
            var       firstRetrievedInstance = Substitute.For <IPullRequest>();

            // This is a hack relying on the fact that client code can add to this dictionary...
            systemUnderTest.Unapproved.AddOrUpdate(testKey, firstRetrievedInstance, (i, existingValue) => firstRetrievedInstance);
            var secondRetrievedInstance = Substitute.For <IPullRequest>();

            secondRetrievedInstance.Id.Returns(testKey);
            var activePullRequests = new[] { secondRetrievedInstance };

            systemUnderTest.EnsureActivePrsArePresent(activePullRequests);

            Assert.That(systemUnderTest.Unapproved[testKey], Is.EqualTo(secondRetrievedInstance));
        }
Esempio n. 3
0
        public void TestEnsureActivePrsArePresent_WhenAnExistingPRIsStillPresent_ReleasesPreviousVersion()
        {
            const int testId           = 134907;
            var       systemUnderTest  = new TfProject(new TeamProject(), _tfsConnection, _logger);
            var       firstVersionOfPr = Substitute.For <IPullRequest>();

            firstVersionOfPr.Id.Returns(testId);
            systemUnderTest.Unapproved.AddOrUpdate(testId, firstVersionOfPr, (i, existingValue) => firstVersionOfPr);
            var secondVersionOfPr = Substitute.For <IPullRequest>();

            secondVersionOfPr.Id.Returns(testId);
            var activePullRequests = new[] { secondVersionOfPr };

            systemUnderTest.EnsureActivePrsArePresent(activePullRequests);

            _tfsConnection.Received().ReleasePullRequest(firstVersionOfPr);
        }
Esempio n. 4
0
        public void TestEnsureActivePrsArePresent_WhenThereIsANewUnapprovedPR_WhichMatchesRepoFilter_AddsToUnapproved()
        {
            var systemUnderTest = new TfProject(new TeamProject(), _tfsConnection, _logger);

            Assert.That(systemUnderTest.Unapproved.Count, Is.Zero);

            var pullRequest = Substitute.For <IPullRequest>();

            pullRequest.IsApproved.Returns(false);
            var activePullRequests = new[] { pullRequest };

            systemUnderTest.RepositoryFilter = null; // <-- null filter means no filtering

            systemUnderTest.EnsureActivePrsArePresent(activePullRequests);

            Assert.That(systemUnderTest.Unapproved.Count, Is.EqualTo(1));
        }
Esempio n. 5
0
        public void TestEnsureActivePrsArePresent_WhenThereIsANewApprovedPR_WhichDoesNotMatchRepoFilter_DoesNotAddToApproved()
        {
            var systemUnderTest = new TfProject(new TeamProject(), _tfsConnection, _logger);

            Assert.That(systemUnderTest.Approved.Count, Is.Zero);

            var pullRequest = Substitute.For <IPullRequest>();

            pullRequest.IsApproved.Returns(true);
            var activePullRequests = new [] { pullRequest };
            var filter             = Substitute.For <IRepositoryFilter>();

            filter.IncludesRepo(Arg.Any <ITfGitRepository>()).Returns(false);
            systemUnderTest.RepositoryFilter = filter;

            systemUnderTest.EnsureActivePrsArePresent(activePullRequests);

            Assert.That(systemUnderTest.Approved.Count, Is.EqualTo(0));
        }