Skip to content

Commit

Permalink
Add convenient initialization of TesClient with a TesCredentials (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
BMurri authored Jun 10, 2024
1 parent b9a39c7 commit 3dd23d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tes.SDK.Tests/TesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TesClientTests
public void Initialize()
{
_httpClientMock = new Mock<HttpClient>();
_client = new TesClient(_httpClientMock.Object, new("https://example.com"));
_client = new TesClient(_httpClientMock.Object, new Uri("https://example.com"));
}

[TestCleanup]
Expand Down
15 changes: 15 additions & 0 deletions src/Tes.SDK/TesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ public TesClient(Uri baseUrl, string username, string password)
ArgumentException.ThrowIfNullOrEmpty(password);
}

public TesClient(TesCredentials tesCredentials, string scheme = "https")
: this(new($"{scheme}://{tesCredentials.TesHostname}"), tesCredentials.TesUsername, tesCredentials.TesPassword)
{
ArgumentException.ThrowIfNullOrWhiteSpace(tesCredentials.TesHostname, nameof(tesCredentials));
}

public TesClient(HttpClient httpClient, TesCredentials tesCredentials, string scheme = "https")
: this(httpClient, new($"{scheme}://{tesCredentials.TesHostname}"), tesCredentials.TesUsername, tesCredentials.TesPassword)
{
ArgumentNullException.ThrowIfNull(tesCredentials);
ArgumentException.ThrowIfNullOrWhiteSpace(tesCredentials.TesHostname, nameof(tesCredentials));
ArgumentException.ThrowIfNullOrWhiteSpace(tesCredentials.TesUsername, nameof(tesCredentials));
ArgumentException.ThrowIfNullOrEmpty(tesCredentials.TesPassword, nameof(tesCredentials));
}

private void SetAuthorizationHeader(HttpRequestMessage request)
{
if (!string.IsNullOrWhiteSpace(_username) && !string.IsNullOrEmpty(_password))
Expand Down

0 comments on commit 3dd23d9

Please sign in to comment.