Skip to content

Commit d4e4fa3

Browse files
committed
Add test for CancellationToken
1 parent f0cc850 commit d4e4fa3

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

CloudConvert.Test/IntegrationTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Generic;
1313
using System.Dynamic;
1414
using System.Text.Json;
15+
using System.Threading;
1516

1617
namespace CloudConvert.Test
1718
{
@@ -27,6 +28,28 @@ public void Setup()
2728
_cloudConvertAPI = new CloudConvertAPI(apiKey, true);
2829
}
2930

31+
[TestCase("cancellationtoken")]
32+
public async Task CancellationToken(string streamingMethod)
33+
{
34+
using var cts = new CancellationTokenSource();
35+
var token = cts.Token;
36+
37+
cts.Cancel();
38+
39+
try
40+
{
41+
await _cloudConvertAPI.CreateJobAsync(new JobCreateRequest
42+
{
43+
Tasks = new()
44+
}, token).ConfigureAwait(false);
45+
46+
Assert.Fail("Expected TaskCanceledException");
47+
}
48+
catch (WebApiException ex) when (ex.InnerException is TaskCanceledException)
49+
{
50+
}
51+
}
52+
3053
[TestCase("stream")]
3154
[TestCase("bytes")]
3255
public async Task CreateJob(string streamingMethod)

0 commit comments

Comments
 (0)