11using ModelContextProtocol . Client ;
22using System . Text . Json ;
3- using Xunit ;
43
54namespace NetContextServer . Tests ;
65
76[ Collection ( "NetContextServer Collection" ) ]
8- public class IgnoreOperationTests : IAsyncLifetime
7+ public class IgnoreOperationTests ( NetContextServerFixture fixture ) : IAsyncLifetime
98{
10- private readonly IMcpClient _client ;
11- private readonly string _testDir ;
9+ private readonly IMcpClient _client = fixture . Client ;
10+ private readonly string _testDir = Path . Combine ( Path . GetTempPath ( ) , "NetContextServerTests_" + Guid . NewGuid ( ) ) ;
11+
12+ private static readonly JsonSerializerOptions DefaultJsonOptions = new ( )
13+ {
14+ PropertyNameCaseInsensitive = true ,
15+ PropertyNamingPolicy = JsonNamingPolicy . CamelCase
16+ } ;
1217
1318 private class AddIgnorePatternsResponse
1419 {
15- public string [ ] InvalidPatterns { get ; set ; } = Array . Empty < string > ( ) ;
16- public string [ ] ValidPatternsAdded { get ; set ; } = Array . Empty < string > ( ) ;
17- public string [ ] AllPatterns { get ; set ; } = Array . Empty < string > ( ) ;
20+ public string [ ] InvalidPatterns { get ; set ; } = [ ] ;
21+ public string [ ] ValidPatternsAdded { get ; set ; } = [ ] ;
22+ public string [ ] AllPatterns { get ; set ; } = [ ] ;
1823 }
1924
2025 private class IgnorePatternsResponse
2126 {
22- public string [ ] DefaultPatterns { get ; set ; } = Array . Empty < string > ( ) ;
23- public string [ ] UserPatterns { get ; set ; } = Array . Empty < string > ( ) ;
27+ public string [ ] DefaultPatterns { get ; set ; } = [ ] ;
28+ public string [ ] UserPatterns { get ; set ; } = [ ] ;
2429 }
2530
2631 private class ErrorResponse
2732 {
2833 public string Error { get ; set ; } = string . Empty ;
2934 }
3035
31- public IgnoreOperationTests ( NetContextServerFixture fixture )
32- {
33- _client = fixture . Client ;
34- _testDir = Path . Combine ( Path . GetTempPath ( ) , "NetContextServerTests_" + Guid . NewGuid ( ) ) ;
35- }
36-
3736 public async Task InitializeAsync ( )
3837 {
3938 Directory . CreateDirectory ( _testDir ) ;
@@ -85,14 +84,8 @@ public async Task AddIgnorePatterns_AddsNewPatterns()
8584
8685 // Debug output
8786 Console . WriteLine ( $ "Actual JSON response: { content . Text } ") ;
88-
89- var options = new JsonSerializerOptions
90- {
91- PropertyNameCaseInsensitive = true ,
92- PropertyNamingPolicy = JsonNamingPolicy . CamelCase
93- } ;
9487
95- var response = JsonSerializer . Deserialize < AddIgnorePatternsResponse > ( content . Text , options ) ;
88+ var response = JsonSerializer . Deserialize < AddIgnorePatternsResponse > ( content . Text , DefaultJsonOptions ) ;
9689 Assert . NotNull ( response ) ;
9790 Assert . Empty ( response . InvalidPatterns ) ;
9891 Assert . Equal ( patterns . Length , response . ValidPatternsAdded . Length ) ;
@@ -110,21 +103,15 @@ await _client.CallToolAsync("add_ignore_patterns",
110103
111104 // Act
112105 var result = await _client . CallToolAsync ( "clear_ignore_patterns" ,
113- new Dictionary < string , object > ( ) ) ;
106+ [ ] ) ;
114107
115108 // Assert
116109 Assert . NotNull ( result ) ;
117110 var content = result . Content . FirstOrDefault ( c => c . Type == "text" ) ;
118111 Assert . NotNull ( content ) ;
119112 Assert . NotNull ( content . Text ) ;
120-
121- var options = new JsonSerializerOptions
122- {
123- PropertyNameCaseInsensitive = true ,
124- PropertyNamingPolicy = JsonNamingPolicy . CamelCase
125- } ;
126113
127- var response = JsonSerializer . Deserialize < IgnorePatternsResponse > ( content . Text , options ) ;
114+ var response = JsonSerializer . Deserialize < IgnorePatternsResponse > ( content . Text , DefaultJsonOptions ) ;
128115 Assert . NotNull ( response ) ;
129116 Assert . NotEmpty ( response . DefaultPatterns ) ;
130117 Assert . Empty ( response . UserPatterns ) ;
@@ -140,21 +127,15 @@ await _client.CallToolAsync("add_ignore_patterns",
140127
141128 // Act
142129 var result = await _client . CallToolAsync ( "get_ignore_patterns" ,
143- new Dictionary < string , object > ( ) ) ;
130+ [ ] ) ;
144131
145132 // Assert
146133 Assert . NotNull ( result ) ;
147134 var content = result . Content . FirstOrDefault ( c => c . Type == "text" ) ;
148135 Assert . NotNull ( content ) ;
149136 Assert . NotNull ( content . Text ) ;
150-
151- var options = new JsonSerializerOptions
152- {
153- PropertyNameCaseInsensitive = true ,
154- PropertyNamingPolicy = JsonNamingPolicy . CamelCase
155- } ;
156137
157- var response = JsonSerializer . Deserialize < IgnorePatternsResponse > ( content . Text , options ) ;
138+ var response = JsonSerializer . Deserialize < IgnorePatternsResponse > ( content . Text , DefaultJsonOptions ) ;
158139 Assert . NotNull ( response ) ;
159140 Assert . NotEmpty ( response . DefaultPatterns ) ;
160141 Assert . Equal ( 2 , response . UserPatterns . Length ) ;
@@ -191,9 +172,9 @@ await _client.CallToolAsync("add_ignore_patterns",
191172
192173 private class RemoveIgnorePatternsResponse
193174 {
194- public string [ ] RemovedPatterns { get ; set ; } = Array . Empty < string > ( ) ;
195- public string [ ] NotFoundPatterns { get ; set ; } = Array . Empty < string > ( ) ;
196- public string [ ] DefaultPatternsSkipped { get ; set ; } = Array . Empty < string > ( ) ;
197- public string [ ] AllPatterns { get ; set ; } = Array . Empty < string > ( ) ;
175+ public string [ ] RemovedPatterns { get ; set ; } = [ ] ;
176+ public string [ ] NotFoundPatterns { get ; set ; } = [ ] ;
177+ public string [ ] DefaultPatternsSkipped { get ; set ; } = [ ] ;
178+ public string [ ] AllPatterns { get ; set ; } = [ ] ;
198179 }
199180}
0 commit comments