public async Task WhenThereAreUpdates_CountIsAsExpected(
            int numberOfUpdates,
            int existingCommitsPerBranch,
            bool consolidateUpdates,
            bool pullRequestExists,
            int expectedUpdates,
            int expectedPrs
            )
        {
            var updateSelection      = Substitute.For <IPackageUpdateSelection>();
            var collaborationFactory = Substitute.For <ICollaborationFactory>();
            var gitDriver            = Substitute.For <IGitDriver>();
            var existingCommitFilder = Substitute.For <IExistingCommitFilter>();

            UpdateSelectionAll(updateSelection);

            gitDriver.GetCurrentHead().Returns("def");
            gitDriver.CheckoutNewBranch(Arg.Any <string>()).Returns(true);

            collaborationFactory
            .CollaborationPlatform
            .PullRequestExists(Arg.Any <ForkData>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(pullRequestExists);

            var packageUpdater = new PackageUpdater(collaborationFactory,
                                                    existingCommitFilder,
                                                    Substitute.For <IUpdateRunner>(),
                                                    Substitute.For <INuKeeperLogger>());

            var updates = Enumerable.Range(1, numberOfUpdates)
                          .Select(_ => PackageUpdates.UpdateSet())
                          .ToList();

            var filteredUpdates = updates.Skip(existingCommitsPerBranch).ToList().AsReadOnly();

            existingCommitFilder.Filter(Arg.Any <IGitDriver>(), Arg.Any <IReadOnlyCollection <PackageUpdateSet> >(), Arg.Any <string>(), Arg.Any <string>()).Returns(filteredUpdates);

            var settings = MakeSettings(consolidateUpdates);

            var(repoUpdater, _) = MakeRepositoryUpdater(
                updateSelection, updates, packageUpdater);

            var repo = MakeRepositoryData();

            var count = await repoUpdater.Run(gitDriver, repo, settings);

            Assert.That(count, Is.EqualTo(expectedUpdates), "Returned count of updates");

            await collaborationFactory.CollaborationPlatform.Received(expectedPrs)
            .OpenPullRequest(
                Arg.Any <ForkData>(),
                Arg.Any <PullRequestRequest>(),
                Arg.Any <IEnumerable <string> >());

            await gitDriver.Received(expectedUpdates).Commit(Arg.Any <string>());
        }
        public async Task WhenThereIsAnUpdate_CountIsOne()
        {
            var updateSelection = Substitute.For <IPackageUpdateSelection>();

            UpdateSelectionAll(updateSelection);

            var updates = PackageUpdates.UpdateSet()
                          .InList();

            var(repoUpdater, packageUpdater) = MakeRepositoryUpdater(
                updateSelection, updates);

            var git  = Substitute.For <IGitDriver>();
            var repo = MakeRepositoryData();

            var count = await repoUpdater.Run(git, repo, MakeSettings());

            Assert.That(count, Is.EqualTo(1));
            await AssertReceivedMakeUpdate(packageUpdater, 1);
        }
Example #3
0
        public async Task WhenThereAreUpdates_CountIsAsExpected(int numberOfUpdates, bool consolidateUpdates, int expectedUpdates, int expectedPrs)
        {
            var updateSelection      = Substitute.For <IPackageUpdateSelection>();
            var collaborationFactory = Substitute.For <ICollaborationFactory>();
            var gitDriver            = Substitute.For <IGitDriver>();

            UpdateSelectionAll(updateSelection);

            var packageUpdater = new PackageUpdater(collaborationFactory,
                                                    Substitute.For <IUpdateRunner>(),
                                                    Substitute.For <INuKeeperLogger>());

            var updates = Enumerable.Range(1, numberOfUpdates)
                          .Select(_ => PackageUpdates.UpdateSet())
                          .ToList();

            var settings = MakeSettings(consolidateUpdates);

            var(repoUpdater, _) = MakeRepositoryUpdater(
                updateSelection, updates, packageUpdater);

            var repo = MakeRepositoryData();

            gitDriver.GetCurrentHead().Returns("def");

            var count = await repoUpdater.Run(gitDriver, repo, settings);

            Assert.That(count, Is.EqualTo(expectedUpdates));

            await collaborationFactory.CollaborationPlatform.Received(expectedPrs)
            .OpenPullRequest(
                Arg.Any <ForkData>(),
                Arg.Any <PullRequestRequest>(),
                Arg.Any <IEnumerable <string> >());

            gitDriver.Received(numberOfUpdates)
            .Commit(Arg.Any <string>());
        }
        public async Task WhenUpdatesAreFilteredOut_CountIsZero()
        {
            var updateSelection = Substitute.For <IPackageUpdateSelection>();

            UpdateSelectionNone(updateSelection);

            var twoUpdates = new List <PackageUpdateSet>
            {
                PackageUpdates.UpdateSet(),
                PackageUpdates.UpdateSet()
            };

            var(repoUpdater, packageUpdater) = MakeRepositoryUpdater(
                updateSelection,
                twoUpdates);

            var git  = Substitute.For <IGitDriver>();
            var repo = MakeRepositoryData();

            var count = await repoUpdater.Run(git, repo, MakeSettings());

            Assert.That(count, Is.EqualTo(0));
            await AssertDidNotReceiveMakeUpdate(packageUpdater);
        }