-
Notifications
You must be signed in to change notification settings - Fork 693
Expand file tree
/
Copy pathClientCompletionDetailsTests.cs
More file actions
137 lines (115 loc) · 4.31 KB
/
ClientCompletionDetailsTests.cs
File metadata and controls
137 lines (115 loc) · 4.31 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using ModelContextProtocol.Client;
namespace ModelContextProtocol.Tests.Client;
public class ClientCompletionDetailsTests
{
[Fact]
public void TransportClosedException_ExposesDetails()
{
var details = new StdioClientCompletionDetails
{
ExitCode = 42,
ProcessId = 12345,
StandardErrorTail = ["error line"],
Exception = new IOException("process exited"),
};
var exception = new TransportClosedException(details);
Assert.IsType<StdioClientCompletionDetails>(exception.Details);
var stdioDetails = (StdioClientCompletionDetails)exception.Details;
Assert.Equal(42, stdioDetails.ExitCode);
Assert.Equal(12345, stdioDetails.ProcessId);
Assert.Equal(["error line"], stdioDetails.StandardErrorTail);
Assert.Equal("process exited", exception.Message);
Assert.IsType<IOException>(exception.InnerException);
}
[Fact]
public void TransportClosedException_WithNullException_HasDefaultMessage()
{
var details = new ClientCompletionDetails();
var exception = new TransportClosedException(details);
Assert.Equal("The transport was closed.", exception.Message);
Assert.Null(exception.InnerException);
Assert.Same(details, exception.Details);
}
[Fact]
public void TransportClosedException_IsIOException()
{
var details = new ClientCompletionDetails();
IOException exception = new TransportClosedException(details);
Assert.IsType<TransportClosedException>(exception);
}
[Fact]
public void ClientCompletionDetails_PropertiesRoundtrip()
{
var exception = new InvalidOperationException("test");
var details = new ClientCompletionDetails
{
Exception = exception,
};
Assert.Same(exception, details.Exception);
}
[Fact]
public void ClientCompletionDetails_DefaultsToNull()
{
var details = new ClientCompletionDetails();
Assert.Null(details.Exception);
}
[Fact]
public void StdioClientCompletionDetails_PropertiesRoundtrip()
{
var exception = new IOException("process exited");
string[] stderrLines = ["error line 1", "error line 2"];
var details = new StdioClientCompletionDetails
{
Exception = exception,
ProcessId = 12345,
ExitCode = 42,
StandardErrorTail = stderrLines,
};
Assert.Same(exception, details.Exception);
Assert.Equal(12345, details.ProcessId);
Assert.Equal(42, details.ExitCode);
Assert.Same(stderrLines, details.StandardErrorTail);
}
[Fact]
public void StdioClientCompletionDetails_DefaultsToNull()
{
var details = new StdioClientCompletionDetails();
Assert.Null(details.Exception);
Assert.Null(details.ProcessId);
Assert.Null(details.ExitCode);
Assert.Null(details.StandardErrorTail);
}
[Fact]
public void StdioClientCompletionDetails_IsClientCompletionDetails()
{
ClientCompletionDetails details = new StdioClientCompletionDetails { ExitCode = 1 };
var stdio = Assert.IsType<StdioClientCompletionDetails>(details);
Assert.Equal(1, stdio.ExitCode);
}
[Fact]
public void HttpClientCompletionDetails_PropertiesRoundtrip()
{
var exception = new HttpRequestException("connection refused");
var details = new HttpClientCompletionDetails
{
Exception = exception,
HttpStatusCode = System.Net.HttpStatusCode.NotFound,
};
Assert.Same(exception, details.Exception);
Assert.Equal(System.Net.HttpStatusCode.NotFound, details.HttpStatusCode);
}
[Fact]
public void HttpClientCompletionDetails_DefaultsToNull()
{
var details = new HttpClientCompletionDetails();
Assert.Null(details.Exception);
Assert.Null(details.HttpStatusCode);
}
[Fact]
public void HttpClientCompletionDetails_IsClientCompletionDetails()
{
ClientCompletionDetails details = new HttpClientCompletionDetails { HttpStatusCode = System.Net.HttpStatusCode.NotFound };
var http = Assert.IsType<HttpClientCompletionDetails>(details);
Assert.Equal(System.Net.HttpStatusCode.NotFound, http.HttpStatusCode);
}
}