private PullRequestsDetailViewModel CreateSutWithData( long id, GitPullRequest pullRequest, ConnectionData connectionData ) { IEnumerable <GitCommit> commits = new List <GitCommit>() { new GitCommit() }; IEnumerable <GitComment> comments = new List <GitComment>() { new GitComment() }; IEnumerable <FileDiff> filesDiff = new List <FileDiff>() { new FileDiff() }; _userInfoService.Stub(x => x.ConnectionData).Return(connectionData); _userInfoService.Stub(x => x.CurrentTheme).Return(Theme.Light); _gitClientService.Expect(x => x.GetPullRequest(id)).Return(pullRequest.FromTaskAsync()); _gitClientService.Expect(x => x.GetPullRequestComments(id)).Return(comments.FromTaskAsync()); _gitClientService.Expect(x => x.GetPullRequestCommits(id)).Return(commits.FromTaskAsync()); _gitClientService.Expect(x => x.GetPullRequestDiff(id)).Return(filesDiff.FromTaskAsync()); _pullRequestDiffViewModel.Expect(x => x.AddFileDiffs(filesDiff)); _pullRequestDiffViewModel.Expect(x => x.UpdateComments(id)).Return(comments.FromTaskAsync()); return(CreateSut()); }
private PullRequestsDetailViewModel CreateSutWithData( long id, GitPullRequest pullRequest, ConnectionData connectionData ) { IEnumerable <GitCommit> commits = new List <GitCommit>() { new GitCommit() }; IEnumerable <GitComment> comments = new List <GitComment>() { new GitComment() }; IEnumerable <ICommentTree> commentTree = new List <ICommentTree>() { new CommentTree() }; IEnumerable <ITreeFile> filesTree = new List <ITreeFile>() { new TreeDirectory("root") }; IEnumerable <FileDiff> filesDiff = new List <FileDiff>() { new FileDiff() }; _userInfoService.Stub(x => x.ConnectionData).Return(connectionData); _userInfoService.Stub(x => x.CurrentTheme).Return(Theme.Light); _gitClientService.Expect(x => x.GetPullRequest(id)).Return(pullRequest.FromTaskAsync()); _gitClientService.Expect(x => x.GetPullRequestComments(id)).Return(comments.FromTaskAsync()); _gitClientService.Expect(x => x.GetPullRequestCommits(id)).Return(commits.FromTaskAsync()); _gitClientService.Expect(x => x.GetPullRequestDiff(id)).Return(filesDiff.FromTaskAsync()); _treeStructureGenerator.Expect(x => x.CreateFileTree(filesDiff)).Return(filesTree); _treeStructureGenerator.Expect(x => x.CreateCommentTree(Arg <IEnumerable <GitComment> > .Is.Anything, Arg <Theme> .Is.Anything, Arg <char> .Is.Anything)) .Return(commentTree); return(CreateSut()); }
public void Initialize_PullRequestAlreadyExists_PullRequestDataShouldBeLoaded() { var remoteBranches = GetRemoteBranches(); var activeRepository = GetActiveRepo(); activeRepository.Branches.First(x => x.IsHead).TrackedBranchName = "RemoteHeadBranchName"; var pullRequest = new GitPullRequest("Title", "Desc", new GitBranch() { Name = "SrcBranch" }, new GitBranch() { Name = "DestinationBranch" }) { Author = new GitUser() { Username = "******" }, Reviewers = new Dictionary <GitUser, bool>() { [new GitUser() { Username = "******" }] = true, [new GitUser() { Username = "******" }] = true } }; IEnumerable <GitCommit> commits = new List <GitCommit>() { new GitCommit() }; IEnumerable <FileDiff> fileDiffs = new List <FileDiff>() { new FileDiff() }; List <ITreeFile> treeFiles = new List <ITreeFile>() { new TreeDirectory("name") }; _gitService.Expect(x => x.GetActiveRepository()).Return(activeRepository); _gitClientService.Expect(x => x.GetBranches()).Return(remoteBranches.FromTaskAsync()); var srcBranch = remoteBranches.First(x => x.Name == "RemoteHeadBranchName"); var dstBranch = remoteBranches.First(x => x.Name == "RemoteDefaultBranchName"); _gitClientService.Expect(x => x.GetPullRequestForBranches(srcBranch.Name, dstBranch.Name)) .Return(pullRequest.FromTaskAsync()); _gitClientService.Expect(x => x.GetCommitsRange(srcBranch, dstBranch)).Return(commits.FromTaskAsync()); _gitClientService.Expect(x => x.GetCommitsDiff(srcBranch.Target.Hash, dstBranch.Target.Hash)) .Return(fileDiffs.FromTaskAsync()); _treeStructureGenerator.Expect(x => x.CreateFileTree(fileDiffs)).Return(treeFiles); _sut.Initialize(); Assert.That(_sut.PullRequestDiffModel.Commits, Is.EqualTo(commits)); Assert.That(_sut.PullRequestDiffModel.FilesTree, Is.EqualTo(treeFiles)); Assert.That(_sut.PullRequestDiffModel.FileDiffs, Is.EqualTo(fileDiffs)); Assert.That(_sut.Title, Is.EqualTo("Title")); Assert.That(_sut.Description, Is.EqualTo("Desc")); Assert.That(_sut.SelectedReviewers.Count, Is.EqualTo(1)); Assert.That(_sut.RemotePullRequest, Is.EqualTo(pullRequest)); }