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());
        }
        public void Initialize_RepositoriesReturned_ShouldBeAssignedToViewModel()
        {
            IEnumerable <GitRemoteRepository> repositories = new List <GitRemoteRepository>()
            {
                new GitRemoteRepository()
            };

            _gitClientService.Expect(x => x.GetAllRepositories()).Return(repositories.FromTaskAsync());

            _sut.Initialize();

            Assert.That(_sut.Repositories, Is.EqualTo(repositories));
        }
Beispiel #3
0
        public void LogoutCommand_ShouldLogoutGitClient()
        {
            _gitClientService.Expect(x => x.Logout()).Repeat.Once();

            var sut = CreateSut();

            sut.LogoutCommand.Execute(null);

            _gitClientService.VerifyAllExpectations();
        }
Beispiel #4
0
        public void CreateCommand_InvokedAndRaisedException_ShouldSetErrorMessage()
        {
            _gitClientService.Expect(x => x.CreateRepositoryAsync(Arg <GitRemoteRepository> .Is.Anything))
            .Throw(new Exception());

            _sut.Initialize();
            _sut.ErrorMessage = null;
            _sut.CreateCommand.Execute(null);
            Assert.IsNotNull(_sut.ErrorMessage);
        }
Beispiel #5
0
        public void Initialize_DataReceived_ShouldLoadAuthorsAndPullRequests()
        {
            IEnumerable<GitUser> authors = new List<GitUser>() { new GitUser() { Uuid = "Author1" } };
            List<GitPullRequest> pullRequests = new List<GitPullRequest>()
            {
                new GitPullRequest("Title", "Description", new GitBranch(){Name="SourceBranch"}, new GitBranch() { Name = "DestinationBranch" }),
                new GitPullRequest("Title2", "Description", new GitBranch(){Name="SourceBranch"}, new GitBranch() { Name = "DestinationBranch" }),
            };
            var iterator = new PageIterator<GitPullRequest>() { Values = pullRequests };

            using (_sut.SuppressChangeNotifications())
            {
                _sut.SelectedStatus = GitPullRequestStatus.Open;
                _sut.SelectedAuthor = authors.First();
            }

            _gitClientService.Expect(x => x.GetPullRequestsAuthors()).Return(authors.FromTaskAsync());
            _gitClientService.Expect(x => x.GetPullRequestsPage(
                state: _sut.SelectedStatus,
                author: _sut.SelectedAuthor.Uuid,
                limit: 50,
                page: 1
                )).Return(iterator.FromTaskAsync());

            _sut.Initialize();

            Assert.AreEqual(2, _sut.GitPullRequests.Count);
            Assert.AreEqual(1, _sut.Authors.Count);
        }
Beispiel #6
0
        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_TeamsLoadedCorrectly_ShouldAssignTeamNamesAndCurrentUserToViewModel()
        {
            IEnumerable <GitTeam> teams = new List <GitTeam>()
            {
                new GitTeam()
                {
                    Name = "TeamName"
                }
            };
            var connectionData = new ConnectionData()
            {
                UserName = "******", IsLoggedIn = true
            };

            _gitClientService.Expect(x => x.GetTeams()).Return(teams.FromTaskAsync());
            _userInfoService.Stub(x => x.ConnectionData).Return(connectionData);

            _sut.Initialize();

            CollectionAssert.AreEqual(new[] { "UserName", "TeamName" }, _sut.Owners);
            Assert.AreEqual("UserName", _sut.SelectedOwner);
        }
        public void Initialize_CorrectSetup_BranchesShouldBeLoaded()
        {
            var remoteBranches = GetRemoteBranches();

            var activeRepository = GetActiveRepo();

            activeRepository.Branches.First(x => x.IsHead).TrackedBranchName = "RemoteHeadBranchName";

            _gitService.Expect(x => x.GetActiveRepository()).Return(activeRepository);
            _gitClientService.Expect(x => x.GetBranches()).Return(remoteBranches.FromTaskAsync());

            _sut.Initialize();

            Assert.That(_sut.SourceBranch, Is.EqualTo(remoteBranches.First(x => x.Name == "RemoteHeadBranchName")));
            Assert.That(_sut.DestinationBranch,
                        Is.EqualTo(remoteBranches.First(x => x.Name == "RemoteDefaultBranchName")));
        }