Skip to content

Commit 5cc2fc3

Browse files
committed
Address CodeRabbit review feedback
1 parent 9724fa7 commit 5cc2fc3

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

examples/EncryptPdf/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
static async Task<string> CreateEncryptedPdf(string destinationDirectory, GotenbergSharpClientOptions options)
2424
{
25-
using var handler = new HttpClientHandler();
26-
using var authHandler = !string.IsNullOrWhiteSpace(options.BasicAuthUsername) && !string.IsNullOrWhiteSpace(options.BasicAuthPassword)
27-
? new BasicAuthHandler(options.BasicAuthUsername, options.BasicAuthPassword) { InnerHandler = handler }
28-
: null;
25+
var handler = new HttpClientHandler();
26+
HttpMessageHandler effectiveHandler = handler;
27+
if (!string.IsNullOrWhiteSpace(options.BasicAuthUsername) && !string.IsNullOrWhiteSpace(options.BasicAuthPassword))
28+
effectiveHandler = new BasicAuthHandler(options.BasicAuthUsername, options.BasicAuthPassword) { InnerHandler = handler };
2929

30-
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
30+
using var httpClient = new HttpClient(effectiveHandler, disposeHandler: true)
3131
{
3232
BaseAddress = options.ServiceUrl,
3333
Timeout = options.TimeOut

test/GotenbergSharpClient.Tests/EncryptionOptionsTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void SetUserPassword_WithEmptyString_ThrowsArgumentException()
106106
#region HTTP Content Serialization Tests
107107

108108
[Test]
109-
public void UserPassword_SerializesToCorrectHttpContent()
109+
public async Task UserPassword_SerializesToCorrectHttpContent()
110110
{
111111
var options = new PdfOutputOptions
112112
{
@@ -118,11 +118,11 @@ public void UserPassword_SerializesToCorrectHttpContent()
118118
c.Headers.ContentDisposition?.Name == "userPassword");
119119

120120
content.Should().NotBeNull();
121-
content!.ReadAsStringAsync().Result.Should().Be("openme");
121+
(await content!.ReadAsStringAsync()).Should().Be("openme");
122122
}
123123

124124
[Test]
125-
public void OwnerPassword_SerializesToCorrectHttpContent()
125+
public async Task OwnerPassword_SerializesToCorrectHttpContent()
126126
{
127127
var options = new PdfOutputOptions
128128
{
@@ -134,7 +134,7 @@ public void OwnerPassword_SerializesToCorrectHttpContent()
134134
c.Headers.ContentDisposition?.Name == "ownerPassword");
135135

136136
content.Should().NotBeNull();
137-
content!.ReadAsStringAsync().Result.Should().Be("editme");
137+
(await content!.ReadAsStringAsync()).Should().Be("editme");
138138
}
139139

140140
[Test]
@@ -154,6 +154,7 @@ public void NullPasswords_NotIncludedInHttpContent()
154154

155155
#region Integration Tests
156156

157+
[Category("Integration")]
157158
[Test]
158159
public async Task HtmlToPdf_WithEncryption_Succeeds()
159160
{

0 commit comments

Comments
 (0)