Skip to content

Commit 480e387

Browse files
committed
Address CodeRabbit review feedback
1 parent 27956cf commit 480e387

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

examples/ChromiumFeatures/Program.cs

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

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

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

test/GotenbergSharpClient.Tests/ChromiumMissingFieldsIntegrationTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void SetUp()
3333
_client = serviceProvider.GetRequiredService<Gotenberg.Sharp.API.Client.GotenbergSharpClient>();
3434
}
3535

36+
[Category("Integration")]
3637
[Test]
3738
public async Task HtmlToPdf_WithWaitForSelector_Succeeds()
3839
{
@@ -48,6 +49,7 @@ public async Task HtmlToPdf_WithWaitForSelector_Succeeds()
4849
result.Length.Should().BeGreaterThan(0);
4950
}
5051

52+
[Category("Integration")]
5153
[Test]
5254
public async Task HtmlToPdf_WithEmulatedMediaFeatures_Succeeds()
5355
{
@@ -63,6 +65,7 @@ public async Task HtmlToPdf_WithEmulatedMediaFeatures_Succeeds()
6365
result.Length.Should().BeGreaterThan(0);
6466
}
6567

68+
[Category("Integration")]
6669
[Test]
6770
public async Task HtmlToPdf_WithFailOnHttpStatusCodes_Succeeds()
6871
{
@@ -78,6 +81,7 @@ public async Task HtmlToPdf_WithFailOnHttpStatusCodes_Succeeds()
7881
result.Length.Should().BeGreaterThan(0);
7982
}
8083

84+
[Category("Integration")]
8185
[Test]
8286
public async Task HtmlToPdf_WithFailOnResourceLoadingFailed_Succeeds()
8387
{
@@ -93,6 +97,7 @@ public async Task HtmlToPdf_WithFailOnResourceLoadingFailed_Succeeds()
9397
result.Length.Should().BeGreaterThan(0);
9498
}
9599

100+
[Category("Integration")]
96101
[Test]
97102
public async Task HtmlToPdf_WithAllNewFields_Succeeds()
98103
{

test/GotenbergSharpClient.Tests/ChromiumMissingFieldsTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void FailOnResourceLoadingFailed_SetsPropertyToTrue()
144144
#region HTTP Content Serialization Tests
145145

146146
[Test]
147-
public void WaitForSelector_SerializesToCorrectHttpContent()
147+
public async Task WaitForSelector_SerializesToCorrectHttpContent()
148148
{
149149
var behaviors = new HtmlConversionBehaviors
150150
{
@@ -156,11 +156,11 @@ public void WaitForSelector_SerializesToCorrectHttpContent()
156156
c.Headers.ContentDisposition?.Name == "waitForSelector");
157157

158158
content.Should().NotBeNull();
159-
content!.ReadAsStringAsync().Result.Should().Be("#content");
159+
(await content!.ReadAsStringAsync()).Should().Be("#content");
160160
}
161161

162162
[Test]
163-
public void EmulatedMediaFeatures_SerializesToCorrectJsonObject()
163+
public async Task EmulatedMediaFeatures_SerializesToCorrectJsonObject()
164164
{
165165
var behaviors = new HtmlConversionBehaviors
166166
{
@@ -176,7 +176,7 @@ public void EmulatedMediaFeatures_SerializesToCorrectJsonObject()
176176
c.Headers.ContentDisposition?.Name == "emulatedMediaFeatures");
177177

178178
content.Should().NotBeNull();
179-
var json = content!.ReadAsStringAsync().Result;
179+
var json = await content!.ReadAsStringAsync();
180180
var jObject = JObject.Parse(json);
181181

182182
jObject.Should().HaveCount(2);
@@ -185,7 +185,7 @@ public void EmulatedMediaFeatures_SerializesToCorrectJsonObject()
185185
}
186186

187187
[Test]
188-
public void FailOnHttpStatusCodes_SerializesToIntArray()
188+
public async Task FailOnHttpStatusCodes_SerializesToIntArray()
189189
{
190190
var behaviors = new HtmlConversionBehaviors
191191
{
@@ -201,7 +201,7 @@ public void FailOnHttpStatusCodes_SerializesToIntArray()
201201
c.Headers.ContentDisposition?.Name == "failOnHttpStatusCodes");
202202

203203
content.Should().NotBeNull();
204-
var json = content!.ReadAsStringAsync().Result;
204+
var json = await content!.ReadAsStringAsync();
205205
var jArray = JArray.Parse(json);
206206

207207
jArray.Should().HaveCount(2);
@@ -210,7 +210,7 @@ public void FailOnHttpStatusCodes_SerializesToIntArray()
210210
}
211211

212212
[Test]
213-
public void FailOnResourceHttpStatusCodes_SerializesToIntArray()
213+
public async Task FailOnResourceHttpStatusCodes_SerializesToIntArray()
214214
{
215215
var behaviors = new HtmlConversionBehaviors
216216
{
@@ -226,7 +226,7 @@ public void FailOnResourceHttpStatusCodes_SerializesToIntArray()
226226
c.Headers.ContentDisposition?.Name == "failOnResourceHttpStatusCodes");
227227

228228
content.Should().NotBeNull();
229-
var json = content!.ReadAsStringAsync().Result;
229+
var json = await content!.ReadAsStringAsync();
230230
var jArray = JArray.Parse(json);
231231

232232
jArray.Should().HaveCount(2);
@@ -235,7 +235,7 @@ public void FailOnResourceHttpStatusCodes_SerializesToIntArray()
235235
}
236236

237237
[Test]
238-
public void IgnoreResourceHttpStatusDomains_SerializesToStringArray()
238+
public async Task IgnoreResourceHttpStatusDomains_SerializesToStringArray()
239239
{
240240
var behaviors = new HtmlConversionBehaviors
241241
{
@@ -251,7 +251,7 @@ public void IgnoreResourceHttpStatusDomains_SerializesToStringArray()
251251
c.Headers.ContentDisposition?.Name == "ignoreResourceHttpStatusDomains");
252252

253253
content.Should().NotBeNull();
254-
var json = content!.ReadAsStringAsync().Result;
254+
var json = await content!.ReadAsStringAsync();
255255
var jArray = JArray.Parse(json);
256256

257257
jArray.Should().HaveCount(2);
@@ -260,7 +260,7 @@ public void IgnoreResourceHttpStatusDomains_SerializesToStringArray()
260260
}
261261

262262
[Test]
263-
public void FailOnResourceLoadingFailed_SerializesToHttpContent()
263+
public async Task FailOnResourceLoadingFailed_SerializesToHttpContent()
264264
{
265265
var behaviors = new HtmlConversionBehaviors
266266
{
@@ -272,7 +272,7 @@ public void FailOnResourceLoadingFailed_SerializesToHttpContent()
272272
c.Headers.ContentDisposition?.Name == "failOnResourceLoadingFailed");
273273

274274
content.Should().NotBeNull();
275-
content!.ReadAsStringAsync().Result.Should().Be("True");
275+
(await content!.ReadAsStringAsync()).Should().Be("True");
276276
}
277277

278278
[Test]

0 commit comments

Comments
 (0)