Example #1
0
        public override GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials credentials)
        {
            var mock = new Mock <GitHttpClient>(MockBehavior.Loose, collectionUrl, credentials.ToVssCredentials());

            mock.Setup(arg => arg.GetPullRequestAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), null, null, null, null, null, null, default(CancellationToken)))
            .ReturnsAsync(() => null);

            mock.Setup(arg => arg.GetPullRequestsAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <GitPullRequestSearchCriteria>(), null, null, 1, null, default(CancellationToken)))
            .ReturnsAsync(() => new List <GitPullRequest>());

            mock = this.Setup(mock);

            return(mock.Object);
        }
        /// <inheritdoc />
        public TestManagementHttpClient CreateTestManagementClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity authorizedIdentity)
        {
            var connection =
                new VssConnection(collectionUrl, credentials.ToVssCredentials());

            authorizedIdentity = connection.AuthorizedIdentity;

            var testClient = connection.GetClient <TestManagementHttpClient>();

            if (testClient == null)
            {
                throw new AzureDevOpsException("Could not retrieve the TestManagementHttpClient object");
            }

            return(testClient);
        }
        public override GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials credentials)
        {
            var mock = new Mock <GitHttpClient>(MockBehavior.Loose, collectionUrl, credentials.ToVssCredentials());

            mock.Setup(arg => arg.GetPullRequestAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), null, null, null, null, null, null, default(CancellationToken)))
            .ReturnsAsync((string project1, string repoId1, int prId, int i1, int i2, int i3, bool b1, bool b2, object o1, CancellationToken c1) => new GitPullRequest
            {
                PullRequestId = prId,
                Status        = PullRequestStatus.Active,
                Repository    = new GitRepository
                {
                    Id   = Guid.NewGuid(),
                    Name = repoId1,
                },
                SourceRefName         = "foo",
                TargetRefName         = "master",
                CodeReviewId          = 123,
                LastMergeSourceCommit = new GitCommitRef {
                    CommitId = "4a92b977"
                },
                LastMergeTargetCommit = new GitCommitRef {
                    CommitId = "78a3c113"
                },
            });

            mock.Setup(arg => arg.GetPullRequestsAsync(
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.IsAny <GitPullRequestSearchCriteria>(),
                           null,
                           null,
                           1,
                           null,
                           default(CancellationToken)))
            .ReturnsAsync((string project2, string repoId2, GitPullRequestSearchCriteria sc, int j1, int j2, int top, object o2, CancellationToken c2)
                          => new List <GitPullRequest>(new[]
            {
                new GitPullRequest
                {
                    PullRequestId = 777,
                    Status        = PullRequestStatus.Active,
                    Repository    = new GitRepository
                    {
                        Id   = Guid.NewGuid(),
                        Name = repoId2,
                    },
                    SourceRefName         = sc.SourceRefName,
                    TargetRefName         = "master",
                    CodeReviewId          = 123,
                    LastMergeSourceCommit = new GitCommitRef {
                        CommitId = "4a92b977"
                    },
                    LastMergeTargetCommit = new GitCommitRef {
                        CommitId = "78a3c113"
                    },
                },
            }));

            mock = this.Setup(mock);

            return(mock.Object);
        }