Clean up (use of) McpException and McpTransportException (#321)
* Clean up (use of) McpException * Replace McpTransportException with InvalidOperationException * Add cancellation test
This commit is contained in:
parent
d65ddce268
commit
7d77be68cf
1 changed files with 231 additions and 219 deletions
|
|
@ -5,6 +5,7 @@ using ModelContextProtocol.Protocol.Transport;
|
|||
using ModelContextProtocol.Protocol.Types;
|
||||
using ModelContextProtocol.Utils.Json;
|
||||
using Moq;
|
||||
using System.IO.Pipelines;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Channels;
|
||||
|
||||
|
|
@ -29,6 +30,31 @@ public class McpClientFactoryTests
|
|||
Assert.NotNull(client);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async Task Cancellation_ThrowsCancellationException(bool preCanceled)
|
||||
{
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
if (preCanceled)
|
||||
{
|
||||
cts.Cancel();
|
||||
}
|
||||
|
||||
Task t = McpClientFactory.CreateAsync(
|
||||
new StreamClientTransport(new Pipe().Writer.AsStream(), new Pipe().Reader.AsStream()),
|
||||
cancellationToken: cts.Token);
|
||||
Assert.False(t.IsCompleted);
|
||||
|
||||
if (!preCanceled)
|
||||
{
|
||||
cts.Cancel();
|
||||
}
|
||||
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(NopTransport))]
|
||||
[InlineData(typeof(FailureTransport))]
|
||||
|
|
|
|||
Loading…
Reference in a new issue