File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
tests/ModelContextProtocol.Tests/Client Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 5
5
using ModelContextProtocol . Protocol . Types ;
6
6
using ModelContextProtocol . Utils . Json ;
7
7
using Moq ;
8
+ using System . IO . Pipelines ;
8
9
using System . Text . Json ;
9
10
using System . Threading . Channels ;
10
11
@@ -29,6 +30,31 @@ public async Task CreateAsync_NopTransport_ReturnsClient()
29
30
Assert . NotNull ( client ) ;
30
31
}
31
32
33
+ [ Theory ]
34
+ [ InlineData ( false ) ]
35
+ [ InlineData ( true ) ]
36
+ public async Task Cancellation_ThrowsCancellationException ( bool preCanceled )
37
+ {
38
+ var cts = new CancellationTokenSource ( ) ;
39
+
40
+ if ( preCanceled )
41
+ {
42
+ cts . Cancel ( ) ;
43
+ }
44
+
45
+ Task t = McpClientFactory . CreateAsync (
46
+ new StreamClientTransport ( new Pipe ( ) . Writer . AsStream ( ) , new Pipe ( ) . Reader . AsStream ( ) ) ,
47
+ cancellationToken : cts . Token ) ;
48
+ Assert . False ( t . IsCompleted ) ;
49
+
50
+ if ( ! preCanceled )
51
+ {
52
+ cts . Cancel ( ) ;
53
+ }
54
+
55
+ await Assert . ThrowsAnyAsync < OperationCanceledException > ( ( ) => t ) ;
56
+ }
57
+
32
58
[ Theory ]
33
59
[ InlineData ( typeof ( NopTransport ) ) ]
34
60
[ InlineData ( typeof ( FailureTransport ) ) ]
You can’t perform that action at this time.
0 commit comments