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 55using ModelContextProtocol . Protocol . Types ;
66using ModelContextProtocol . Utils . Json ;
77using Moq ;
8+ using System . IO . Pipelines ;
89using System . Text . Json ;
910using System . Threading . Channels ;
1011
@@ -29,6 +30,31 @@ public async Task CreateAsync_NopTransport_ReturnsClient()
2930 Assert . NotNull ( client ) ;
3031 }
3132
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+
3258 [ Theory ]
3359 [ InlineData ( typeof ( NopTransport ) ) ]
3460 [ InlineData ( typeof ( FailureTransport ) ) ]
You can’t perform that action at this time.
0 commit comments