-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathSwashbuckle.CancellationToken.Tests.fs
More file actions
43 lines (37 loc) · 1.27 KB
/
Swashbuckle.CancellationToken.Tests.fs
File metadata and controls
43 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Swashbuckle.v3.CancellationTokenTests
open Xunit
open FsUnitTyped
open System
open System.Threading
open Swashbuckle.v3.ReturnControllersTests
[<Fact>]
let ``Call generated method with explicit CancellationToken None``() =
task {
let! result = api.GetApiReturnBoolean(CancellationToken.None)
result |> shouldEqual true
}
[<Fact>]
let ``Call generated method with valid CancellationTokenSource token``() =
task {
use cts = new CancellationTokenSource()
let! result = api.GetApiReturnInt32(cts.Token)
result |> shouldEqual 42
}
[<Fact>]
let ``Call generated method with already-cancelled token raises OperationCanceledException``() =
task {
use cts = new CancellationTokenSource()
cts.Cancel()
try
let! _ = api.GetApiReturnString(cts.Token)
failwith "Expected OperationCanceledException"
with
| :? OperationCanceledException -> ()
| :? System.AggregateException as aex when (aex.InnerException :? OperationCanceledException) -> ()
}
[<Fact>]
let ``Call POST generated method with explicit CancellationToken None``() =
task {
let! result = api.PostApiReturnString(CancellationToken.None)
result |> shouldEqual "Hello world"
}