예제 #1
0
        public async Task OrgModeInvalidReposAreExcluded()
        {
            var inputRepos = new List <Repository>
            {
                RespositoryBuilder.MakeRepository("http://a.com/repo1", "http://a.com/repo1.git", false),
                RespositoryBuilder.MakeRepository("http://b.com/repob", "http://b.com/repob.git", true)
            };
            IReadOnlyList <Repository> readOnlyRepos = inputRepos.AsReadOnly();

            var github = Substitute.For <IGithub>();

            github.GetRepositoriesForOrganisation(Arg.Any <string>())
            .Returns(Task.FromResult(readOnlyRepos));

            var githubRepositoryDiscovery = MakeGithubRepositoryDiscovery(github, OrgModeSettings());

            var repos = await githubRepositoryDiscovery.GetRepositories();

            Assert.That(repos, Is.Not.Null);
            Assert.That(repos, Is.Not.Empty);
            Assert.That(repos.Count(), Is.EqualTo(1));

            var firstRepo = repos.First();

            Assert.That(firstRepo.RepositoryName, Is.EqualTo(inputRepos[1].Name));
            Assert.That(firstRepo.GithubUri.ToString(), Is.EqualTo(inputRepos[1].HtmlUrl));
        }
예제 #2
0
        public async Task FallbackForkIsNotUsedWhenItIsNotPushable()
        {
            var fallbackFork     = DefaultFork();
            var fallbackRepoData = RespositoryBuilder.MakeRepository(true, false);

            var github = Substitute.For <IGithub>();

            github.GetUserRepository(fallbackFork.Owner, fallbackFork.Name)
            .Returns(fallbackRepoData);

            var forkFinder = new ForkFinder(github,
                                            MakePreferForkSettings(), new NullNuKeeperLogger());

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.Null);
        }
예제 #3
0
        public async Task SingleRepoOnlyModeWillNotPreferFork()
        {
            var fallbackFork = DefaultFork();

            var userRepo = RespositoryBuilder.MakeRepository();

            var github = Substitute.For <IGithub>();

            github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new ForkFinder(github,
                                            MakeSingleRepoOnlySettings(), new NullNuKeeperLogger());

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.EqualTo(fallbackFork));
        }
예제 #4
0
        public async Task WhenUnsuitableUserForkIsFoundItIsNotUsed()
        {
            var fallbackFork = NoMatchFork();

            var userRepo = RespositoryBuilder.MakeRepository();

            var github = Substitute.For <IGithub>();

            github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new ForkFinder(github,
                                            MakePreferForkSettings(), new NullNuKeeperLogger());

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.EqualTo(fallbackFork));
        }
예제 #5
0
        public async Task WhenSuitableUserForkIsFound_ThatMatchesParentHtmlUrl_ItIsUsedOverFallback()
        {
            var fallbackFork = new ForkData(new Uri(RespositoryBuilder.ParentHtmlUrl), "testOrg", "someRepo");

            var userRepo = RespositoryBuilder.MakeRepository();

            var github = Substitute.For <IGithub>();

            github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new ForkFinder(github,
                                            MakePreferForkSettings(), new NullNuKeeperLogger());

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.Not.EqualTo(fallbackFork));
            AssertForkMatchesRepo(fork, userRepo);
        }
예제 #6
0
        public async Task SingleRepoOnlyModeWillNotUseForkWhenUpstreamIsUnsuitable()
        {
            var fallbackFork = DefaultFork();

            var github = Substitute.For <IGithub>();

            var defaultRepo = RespositoryBuilder.MakeRepository(true, false);

            github.GetUserRepository(fallbackFork.Owner, fallbackFork.Name)
            .Returns(defaultRepo);

            var userRepo = RespositoryBuilder.MakeRepository();

            github.GetUserRepository("testUser", fallbackFork.Name)
            .Returns(userRepo);

            var forkFinder = new ForkFinder(github,
                                            MakeSingleRepoOnlySettings(), new NullNuKeeperLogger());

            var fork = await forkFinder.FindPushFork("testUser", fallbackFork);

            Assert.That(fork, Is.Null);
        }
예제 #7
0
        public async Task WhenUserForkIsNotFoundItIsCreated()
        {
            var fallbackFork = DefaultFork();

            var userRepo = RespositoryBuilder.MakeRepository();

            var github = Substitute.For <IGithub>();

            github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>())
            .Returns((Repository)null);
            github.MakeUserFork(Arg.Any <string>(), Arg.Any <string>())
            .Returns(userRepo);

            var forkFinder = new ForkFinder(github,
                                            MakePreferForkSettings(), new NullNuKeeperLogger());

            var actualFork = await forkFinder.FindPushFork("testUser", fallbackFork);

            await github.Received(1).MakeUserFork(Arg.Any <string>(), Arg.Any <string>());

            Assert.That(actualFork, Is.Not.Null);
            Assert.That(actualFork, Is.Not.EqualTo(fallbackFork));
        }