public async Task FallbackForkIsNotUsedWhenItIsNotPushable() { var fallbackFork = DefaultFork(); var fallbackRepoData = RepositoryBuilder.MakeRepository(true, false); var github = Substitute.For <IGithub>(); github.GetUserRepository(fallbackFork.Owner, fallbackFork.Name) .Returns(fallbackRepoData); var forkFinder = new ForkFinder(github, MakePreferForkSettings(), Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork("testUser", fallbackFork); Assert.That(fork, Is.Null); }
public async Task FallbackForkIsUsedWhenItIsFound() { var fallbackFork = DefaultFork(); var fallbackRepoData = RepositoryBuilder.MakeRepository(); var github = Substitute.For <IGitHub>(); github.GetUserRepository(fallbackFork.Owner, fallbackFork.Name) .Returns(fallbackRepoData); var forkFinder = new ForkFinder(github, Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork(ForkMode.PreferFork, "testUser", fallbackFork); Assert.That(fork, Is.Not.Null); Assert.That(fork, Is.EqualTo(fallbackFork)); }
public async Task SingleRepoOnlyModeWillNotPreferFork() { var fallbackFork = DefaultFork(); var userRepo = RepositoryBuilder.MakeRepository(); var github = Substitute.For <IGitHub>(); github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>()) .Returns(userRepo); var forkFinder = new ForkFinder(github, Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork(ForkMode.SingleRepositoryOnly, "testUser", fallbackFork); Assert.That(fork, Is.EqualTo(fallbackFork)); }
public async Task WhenUnsuitableUserForkIsFoundItIsNotUsed() { var fallbackFork = NoMatchFork(); var userRepo = RepositoryBuilder.MakeRepository(); var github = Substitute.For <IGitHub>(); github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>()) .Returns(userRepo); var forkFinder = new ForkFinder(github, Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork(ForkMode.PreferFork, "testUser", fallbackFork); Assert.That(fork, Is.EqualTo(fallbackFork)); }
public async Task WhenSuitableUserForkIsFound_ThatMatchesParentHtmlUrl_ItIsUsedOverFallback() { var fallbackFork = new ForkData(new Uri(RepositoryBuilder.ParentHtmlUrl), "testOrg", "someRepo"); var userRepo = RepositoryBuilder.MakeRepository(); var github = Substitute.For <IGitHub>(); github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>()) .Returns(userRepo); var forkFinder = new ForkFinder(github, Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork(ForkMode.PreferFork, "testUser", fallbackFork); Assert.That(fork, Is.Not.EqualTo(fallbackFork)); AssertForkMatchesRepo(fork, userRepo); }
public async Task WhenSuitableUserForkIsFoundItIsUsedOverFallback() { var fallbackFork = DefaultFork(); var userRepo = RepositoryBuilder.MakeRepository(); var github = Substitute.For <IGithub>(); github.GetUserRepository(Arg.Any <string>(), Arg.Any <string>()) .Returns(userRepo); var forkFinder = new ForkFinder(github, MakePreferForkSettings(), Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork("testUser", fallbackFork); Assert.That(fork, Is.Not.EqualTo(fallbackFork)); AssertForkMatchesRepo(fork, userRepo); }
private static GitHubEngine MakeGithubEngine( int repoEngineResult, List <RepositorySettings> repos) { var github = Substitute.For <IGitHub>(); var repoDiscovery = Substitute.For <IGitHubRepositoryDiscovery>(); var repoEngine = Substitute.For <IGitHubRepositoryEngine>(); var folders = Substitute.For <IFolderFactory>(); github.GetCurrentUser().Returns( RepositoryBuilder.MakeUser("http://test.user.com")); repoDiscovery.GetRepositories(Arg.Any <IGitHub>(), Arg.Any <SourceControlServerSettings>()) .Returns(repos); repoEngine.Run(null, null, null, null).ReturnsForAnyArgs(repoEngineResult); var engine = new GitHubEngine(github, repoDiscovery, repoEngine, folders, Substitute.For <INuKeeperLogger>()); return(engine); }
public async Task SingleRepoOnlyModeWillNotUseForkWhenUpstreamIsUnsuitable() { var fallbackFork = DefaultFork(); var github = Substitute.For <IGitHub>(); var defaultRepo = RepositoryBuilder.MakeRepository(true, false); github.GetUserRepository(fallbackFork.Owner, fallbackFork.Name) .Returns(defaultRepo); var userRepo = RepositoryBuilder.MakeRepository(); github.GetUserRepository("testUser", fallbackFork.Name) .Returns(userRepo); var forkFinder = new ForkFinder(github, Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork(ForkMode.SingleRepositoryOnly, "testUser", fallbackFork); Assert.That(fork, Is.Null); }
public async Task WhenUserForkIsNotFoundItIsCreated() { var fallbackFork = DefaultFork(); var userRepo = RepositoryBuilder.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, Substitute.For <INuKeeperLogger>()); var actualFork = await forkFinder.FindPushFork(ForkMode.PreferFork, "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)); }
public async Task RepoModeIgnoresIncludesAndExcludes() { var github = Substitute.For <IGitHub>(); var settings = new SourceControlServerSettings { Repository = new RepositorySettings(RepositoryBuilder.MakeRepository(name: "foo")), Scope = ServerScope.Repository, IncludeRepos = new Regex("^foo"), ExcludeRepos = new Regex("^foo") }; var githubRepositoryDiscovery = MakeGithubRepositoryDiscovery(); var reposResponse = await githubRepositoryDiscovery.GetRepositories(github, settings); var repos = reposResponse.ToList(); Assert.That(repos, Is.Not.Null); Assert.That(repos.Count, Is.EqualTo(1)); var firstRepo = repos.First(); Assert.That(firstRepo.RepositoryName, Is.EqualTo("foo")); }
public async Task PreferSingleRepoModeWillUseForkWhenUpstreamIsUnsuitable() { var fallbackFork = DefaultFork(); var github = Substitute.For <IGithub>(); var defaultRepo = RepositoryBuilder.MakeRepository(true, false); github.GetUserRepository(fallbackFork.Owner, fallbackFork.Name) .Returns(defaultRepo); var userRepo = RepositoryBuilder.MakeRepository(); github.GetUserRepository("testUser", fallbackFork.Name) .Returns(userRepo); var forkFinder = new ForkFinder(github, MakePreferSingleRepoSettings(), Substitute.For <INuKeeperLogger>()); var fork = await forkFinder.FindPushFork("testUser", fallbackFork); Assert.That(fork, Is.Not.EqualTo(fallbackFork)); AssertForkMatchesRepo(fork, userRepo); }