Skip to content

Commit 1cf6a25

Browse files
authored
Merge pull request #256 from pascalberger/feature/client-factory-unification
Unify client factory interfaces
2 parents e6f9820 + 2b1516f commit 1cf6a25

File tree

7 files changed

+52
-46
lines changed

7 files changed

+52
-46
lines changed

src/Cake.AzureDevOps/BuildClientFactory.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
/// <inheritdoc />
1010
internal class BuildClientFactory : IBuildClientFactory
1111
{
12-
/// <summary>
13-
/// Creates a client object for communicating with Azure DevOps.
14-
/// </summary>
15-
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
16-
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
17-
/// <param name="authorizedIdentity">Returns identity which is authorized.</param>
18-
/// <returns>Client object for communicating with Azure DevOps.</returns>
12+
/// <inheritdoc/>
13+
public BuildHttpClient CreateBuildClient(Uri collectionUrl, IAzureDevOpsCredentials credentials)
14+
{
15+
return this.CreateBuildClient(collectionUrl, credentials, out _);
16+
}
17+
18+
/// <inheritdoc/>
1919
public BuildHttpClient CreateBuildClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity authorizedIdentity)
2020
{
2121
var connection =
@@ -31,16 +31,5 @@ public BuildHttpClient CreateBuildClient(Uri collectionUrl, IAzureDevOpsCredenti
3131

3232
return buildClient;
3333
}
34-
35-
/// <summary>
36-
/// Creates a client object for communicating with Azure DevOps.
37-
/// </summary>
38-
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
39-
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
40-
/// <returns>Client object for communicating with Azure DevOps.</returns>
41-
public BuildHttpClient CreateBuildClient(Uri collectionUrl, IAzureDevOpsCredentials credentials)
42-
{
43-
return this.CreateBuildClient(collectionUrl, credentials, out _);
44-
}
4534
}
4635
}

src/Cake.AzureDevOps/GitClientFactory.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
/// <inheritdoc />
1010
internal class GitClientFactory : IGitClientFactory
1111
{
12-
/// <summary>
13-
/// Creates a client object for communicating with Azure DevOps.
14-
/// </summary>
15-
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
16-
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
17-
/// <param name="authorizedIdentity">Returns identity which is authorized.</param>
18-
/// <returns>Client object for communicating with Azure DevOps.</returns>
12+
/// <inheritdoc/>
13+
public GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials credentials)
14+
{
15+
return this.CreateGitClient(collectionUrl, credentials, out _);
16+
}
17+
18+
/// <inheritdoc/>
1919
public GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity authorizedIdentity)
2020
{
2121
var connection =
@@ -31,16 +31,5 @@ public GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials
3131

3232
return gitClient;
3333
}
34-
35-
/// <summary>
36-
/// Creates a client object for communicating with Azure DevOps.
37-
/// </summary>
38-
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
39-
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
40-
/// <returns>Client object for communicating with Azure DevOps.</returns>
41-
public GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials credentials)
42-
{
43-
return this.CreateGitClient(collectionUrl, credentials, out _);
44-
}
4534
}
4635
}

src/Cake.AzureDevOps/IBuildClientFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ internal interface IBuildClientFactory
2323
/// </summary>
2424
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
2525
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
26-
/// <param name="identity">Returns identity which is authorized.</param>
26+
/// <param name="authorizedIdentity">Returns identity which is authorized.</param>
2727
/// <returns>The instance of <see cref="BuildHttpClient"/> class.</returns>
28-
BuildHttpClient CreateBuildClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity identity);
28+
BuildHttpClient CreateBuildClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity authorizedIdentity);
2929
}
3030
}

src/Cake.AzureDevOps/IGitClientFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ internal interface IGitClientFactory
2323
/// </summary>
2424
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
2525
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
26-
/// <param name="identity">Returns identity which is authorized.</param>
26+
/// <param name="authorizedIdentity">Returns identity which is authorized.</param>
2727
/// <returns>The instance of <see cref="GitHttpClient"/> class.</returns>
28-
GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity identity);
28+
GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity authorizedIdentity);
2929
}
3030
}

src/Cake.AzureDevOps/ITestManagementClientFactory.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
namespace Cake.AzureDevOps
22
{
33
using System;
4+
using Cake.AzureDevOps.Authentication;
45
using Microsoft.TeamFoundation.TestManagement.WebApi;
5-
using Microsoft.VisualStudio.Services.Common;
6+
using Microsoft.VisualStudio.Services.Identity;
67

78
/// <summary>
89
/// The interface for a Git client factory.
@@ -15,6 +16,15 @@ internal interface ITestManagementClientFactory
1516
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
1617
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
1718
/// <returns>The instance of <see cref="TestManagementHttpClient"/> class.</returns>
18-
TestManagementHttpClient CreateTestManagementClient(Uri collectionUrl, VssCredentials credentials);
19+
TestManagementHttpClient CreateTestManagementClient(Uri collectionUrl, IAzureDevOpsCredentials credentials);
20+
21+
/// <summary>
22+
/// Creates the instance of the <see cref="TestManagementHttpClient"/> class.
23+
/// </summary>
24+
/// <param name="collectionUrl">The URL of the Azure DevOps team project collection.</param>
25+
/// <param name="credentials">The credentials to connect to Azure DevOps.</param>
26+
/// <param name="authorizedIdentity">Returns identity which is authorized.</param>
27+
/// <returns>The instance of <see cref="TestManagementHttpClient"/> class.</returns>
28+
TestManagementHttpClient CreateTestManagementClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity authorizedIdentity);
1929
}
2030
}

src/Cake.AzureDevOps/Pipelines/AzureDevOpsBuild.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public IEnumerable<AzureDevOpsTestRun> GetTestRuns()
417417
return new List<AzureDevOpsTestRun>();
418418
}
419419

420-
using (var testClient = this.testClientFactory.CreateTestManagementClient(this.CollectionUrl, this.credentials.ToVssCredentials()))
420+
using (var testClient = this.testClientFactory.CreateTestManagementClient(this.CollectionUrl, this.credentials))
421421
{
422422
return
423423
testClient

src/Cake.AzureDevOps/TestManagementClientFactory.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
namespace Cake.AzureDevOps
22
{
33
using System;
4+
using Cake.AzureDevOps.Authentication;
45
using Microsoft.TeamFoundation.TestManagement.WebApi;
5-
using Microsoft.VisualStudio.Services.Common;
6+
using Microsoft.VisualStudio.Services.Identity;
7+
using Microsoft.VisualStudio.Services.WebApi;
68

79
/// <inheritdoc />
810
internal class TestManagementClientFactory : ITestManagementClientFactory
911
{
12+
/// <inheritdoc/>
13+
public TestManagementHttpClient CreateTestManagementClient(Uri collectionUrl, IAzureDevOpsCredentials credentials)
14+
{
15+
return this.CreateTestManagementClient(collectionUrl, credentials, out _);
16+
}
17+
1018
/// <inheritdoc />
11-
public TestManagementHttpClient CreateTestManagementClient(Uri collectionUrl, VssCredentials credentials)
19+
public TestManagementHttpClient CreateTestManagementClient(Uri collectionUrl, IAzureDevOpsCredentials credentials, out Identity authorizedIdentity)
1220
{
13-
TestManagementHttpClient testClient = new TestManagementHttpClient(collectionUrl, credentials);
21+
var connection =
22+
new VssConnection(collectionUrl, credentials.ToVssCredentials());
23+
24+
authorizedIdentity = connection.AuthorizedIdentity;
25+
26+
var testClient = connection.GetClient<TestManagementHttpClient>();
27+
if (testClient == null)
28+
{
29+
throw new AzureDevOpsException("Could not retrieve the TestManagementHttpClient object");
30+
}
31+
1432
return testClient;
1533
}
1634
}

0 commit comments

Comments
 (0)