static TestData PrepareTestData( string repoName, string sourceRepoOwner, string sourceBranchName, string targetRepoOwner, string targetBranchName, string remote, bool repoIsFork, bool sourceBranchIsTracking) { var serviceProvider = Substitutes.ServiceProvider; var gitService = serviceProvider.GetGitService(); var gitClient = Substitute.For <IGitClient>(); var notifications = Substitute.For <INotificationService>(); var connection = Substitute.For <IConnection>(); var api = Substitute.For <IApiClient>(); var ms = Substitute.For <IModelService>(); connection.HostAddress.Returns(HostAddress.Create("https://github.com")); // this is the local repo instance that is available via TeamExplorerServiceHolder and friends var activeRepo = Substitute.For <ILocalRepositoryModel>(); activeRepo.LocalPath.Returns(""); activeRepo.Name.Returns(repoName); activeRepo.CloneUrl.Returns(new UriString("http://github.com/" + sourceRepoOwner + "/" + repoName)); activeRepo.Owner.Returns(sourceRepoOwner); Repository githubRepoParent = null; if (repoIsFork) { githubRepoParent = CreateRepository(targetRepoOwner, repoName, id: 1); } var githubRepo = CreateRepository(sourceRepoOwner, repoName, id: 2, parent: githubRepoParent); var sourceBranch = new BranchModel(sourceBranchName, activeRepo); var sourceRepo = new RemoteRepositoryModel(githubRepo); var targetRepo = targetRepoOwner == sourceRepoOwner ? sourceRepo : sourceRepo.Parent; var targetBranch = targetBranchName != targetRepo.DefaultBranch.Name ? new BranchModel(targetBranchName, targetRepo) : targetRepo.DefaultBranch; activeRepo.CurrentBranch.Returns(sourceBranch); api.GetRepository(Args.String, Args.String).Returns(Observable.Return(githubRepo)); ms.ApiClient.Returns(api); // sets up the libgit2sharp repo and branch objects var l2repo = SetupLocalRepoMock(gitClient, gitService, remote, sourceBranchName, sourceBranchIsTracking); return(new TestData { ServiceProvider = serviceProvider, ActiveRepo = activeRepo, L2Repo = l2repo, SourceRepo = sourceRepo, SourceBranch = sourceBranch, TargetRepo = targetRepo, TargetBranch = targetBranch, GitClient = gitClient, GitService = gitService, NotificationService = notifications, Connection = connection, ApiClient = api, ModelService = ms }); }
public void DifferentContentEqualsFalse(long id1, string name1, string url1, long id2, string name2, string url2) { var account = Substitute.For<IAccount>(); var a = new RemoteRepositoryModel(id1, name1, new UriString(url1), false, false, account); var b = new RemoteRepositoryModel(id2, name2, new UriString(url2), false, false, account); Assert.NotEqual(a, b); Assert.False(a == b); Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); }
static TestData PrepareTestData( string repoName, string sourceRepoOwner, string sourceBranchName, string targetRepoOwner, string targetBranchName, string remote, bool repoIsFork, bool sourceBranchIsTracking) { var serviceProvider = Substitutes.ServiceProvider; var gitService = serviceProvider.GetGitService(); var gitClient = Substitute.For<IGitClient>(); var notifications = Substitute.For<INotificationService>(); var host = Substitute.For<IRepositoryHost>(); var api = Substitute.For<IApiClient>(); var ms = Substitute.For<IModelService>(); // this is the local repo instance that is available via TeamExplorerServiceHolder and friends var activeRepo = Substitute.For<ILocalRepositoryModel>(); activeRepo.LocalPath.Returns(""); activeRepo.Name.Returns(repoName); activeRepo.CloneUrl.Returns(new GitHub.Primitives.UriString("http://github.com/" + sourceRepoOwner + "/" + repoName)); activeRepo.Owner.Returns(sourceRepoOwner); Repository githubRepoParent = null; if (repoIsFork) githubRepoParent = CreateRepository(targetRepoOwner, repoName, id: 1); var githubRepo = CreateRepository(sourceRepoOwner, repoName, id: 2, parent: githubRepoParent); var sourceBranch = new BranchModel(sourceBranchName, activeRepo); var sourceRepo = new RemoteRepositoryModel(githubRepo); var targetRepo = targetRepoOwner == sourceRepoOwner ? sourceRepo : sourceRepo.Parent; var targetBranch = targetBranchName != targetRepo.DefaultBranch.Name ? new BranchModel(targetBranchName, targetRepo) : targetRepo.DefaultBranch; activeRepo.CurrentBranch.Returns(sourceBranch); serviceProvider.GetRepositoryHosts().GitHubHost.Returns(host); host.ApiClient.Returns(api); host.ModelService.Returns(ms); api.GetRepository(Args.String, Args.String).Returns(Observable.Return(githubRepo)); // sets up the libgit2sharp repo and branch objects var l2repo = SetupLocalRepoMock(gitClient, gitService, remote, sourceBranchName, sourceBranchIsTracking); return new TestData { ServiceProvider = serviceProvider, ActiveRepo = activeRepo, L2Repo = l2repo, SourceRepo = sourceRepo, SourceBranch = sourceBranch, TargetRepo = targetRepo, TargetBranch = targetBranch, GitClient = gitClient, GitService = gitService, NotificationService = notifications, RepositoryHost = host, ApiClient = api, ModelService = ms }; }
public void DifferentContentEqualsFalse(long id1, string name1, string url1, long id2, string name2, string url2) { var account = Substitute.For <IAccount>(); var a = new RemoteRepositoryModel(id1, name1, new UriString(url1), false, false, account, null); var b = new RemoteRepositoryModel(id2, name2, new UriString(url2), false, false, account, null); Assert.NotEqual(a, b); Assert.False(a == b); Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); }
public void SameContentEqualsTrue2(long id1, string name1, string url1, long id2, string name2, string url2) { var account = Substitute.For <IAccount>(); var a = new RemoteRepositoryModel(id1, name1, new UriString(url1), false, false, account, null); var b = new RemoteRepositoryModel(id2, name2, new UriString(url2), false, false, account, null); Assert.That(a, Is.EqualTo(b)); Assert.False(a == b); Assert.That(a.GetHashCode(), Is.EqualTo(b.GetHashCode())); }
static RemoteRepositoryModel CreateRemoteRepositoryModel(Repository repository) { var ownerAccount = new Models.Account(repository.Owner); var parent = repository.Parent != null?CreateRemoteRepositoryModel(repository.Parent) : null; var model = new RemoteRepositoryModel(repository.Id, repository.Name, repository.CloneUrl, repository.Private, repository.Fork, ownerAccount, parent, repository.DefaultBranch); if (parent != null) { parent.DefaultBranch.DisplayName = parent.DefaultBranch.Id; } return(model); }
/// <inheritdoc/> public async Task InitializeAsync( RemoteRepositoryModel repository, LocalRepositoryModel localRepository, ActorModel currentUser, PullRequestDetailModel model) { await base.InitializeAsync(repository, localRepository, model).ConfigureAwait(true); timeline.Clear(); CommitCount = 0; currentUserModel = currentUser; CurrentUser = new ActorViewModel(currentUser); var commits = new List <CommitSummaryViewModel>(); foreach (var i in model.Timeline) { if (!(i is CommitModel) && commits.Count > 0) { timeline.Add(new CommitListViewModel(commits)); commits.Clear(); } switch (i) { case CommitModel commit: commits.Add(new CommitSummaryViewModel(commit)); ++CommitCount; break; case CommentModel comment: await AddComment(comment).ConfigureAwait(true); break; } } if (commits.Count > 0) { timeline.Add(new CommitListViewModel(commits)); } await AddPlaceholder().ConfigureAwait(true); await usageTracker.IncrementCounter(x => x.NumberOfPRConversationsOpened); }
public async Task InitializeAsync(ILocalRepositoryModel sourceRepository, IAccount destinationAccount, IConnection connection) { var modelService = await modelServiceFactory.CreateAsync(connection); apiClient = modelService.ApiClient; DestinationAccount = destinationAccount; SourceRepository = sourceRepository; DestinationRepository = new RemoteRepositoryModel( 0, sourceRepository.Name, CreateForkUri(sourceRepository.CloneUrl, destinationAccount.Login), false, true, destinationAccount, null); }
public Task InitializeAsync(RemoteRepositoryModel repository, LocalRepositoryModel localRepository, ActorModel currentUser, PullRequestDetailModel model) { throw new NotImplementedException(); }
public void Initialize(LocalRepositoryModel sourceRepository, RemoteRepositoryModel remoteRepository) { }
void ShowSwitchRepositoryPath(RemoteRepositoryModel remoteRepository) { switchPage.Initialize(Repository, remoteRepository); Content = switchPage; }
public void Initialize(LocalRepositoryModel sourceRepository, RemoteRepositoryModel remoteRepository) { SourceRepository = sourceRepository; DestinationRepository = remoteRepository; }