@@ -83,30 +83,15 @@ public void GetToolMetadata_HasInputSchema()
8383
8484 #region Configuration Tests
8585
86- [ TestMethod ]
87- public async Task AggregateRecords_DisabledAtRuntimeLevel_ReturnsToolDisabledError ( )
88- {
89- RuntimeConfig config = CreateConfig ( aggregateRecordsEnabled : false ) ;
90- IServiceProvider sp = CreateServiceProvider ( config ) ;
91- AggregateRecordsTool tool = new ( ) ;
92-
93- JsonDocument args = JsonDocument . Parse ( "{\" entity\" : \" Book\" , \" function\" : \" count\" , \" field\" : \" *\" }" ) ;
94- CallToolResult result = await tool . ExecuteAsync ( args , sp , CancellationToken . None ) ;
95-
96- Assert . IsTrue ( result . IsError == true ) ;
97- JsonElement content = ParseContent ( result ) ;
98- AssertToolDisabledError ( content ) ;
99- }
100-
101- [ TestMethod ]
102- public async Task AggregateRecords_DisabledAtEntityLevel_ReturnsToolDisabledError ( )
86+ [ DataTestMethod ]
87+ [ DataRow ( false , false , DisplayName = "Disabled at runtime level returns ToolDisabled" ) ]
88+ [ DataRow ( true , true , DisplayName = "Disabled at entity level returns ToolDisabled" ) ]
89+ public async Task AggregateRecords_DisabledConfigurations_ReturnToolDisabledError ( bool runtimeEnabled , bool disableAtEntityLevel )
10390 {
104- RuntimeConfig config = CreateConfigWithEntityDmlDisabled ( ) ;
105- IServiceProvider sp = CreateServiceProvider ( config ) ;
106- AggregateRecordsTool tool = new ( ) ;
107-
108- JsonDocument args = JsonDocument . Parse ( "{\" entity\" : \" Book\" , \" function\" : \" count\" , \" field\" : \" *\" }" ) ;
109- CallToolResult result = await tool . ExecuteAsync ( args , sp , CancellationToken . None ) ;
91+ RuntimeConfig config = disableAtEntityLevel
92+ ? CreateConfigWithEntityDmlDisabled ( )
93+ : CreateConfig ( aggregateRecordsEnabled : runtimeEnabled ) ;
94+ CallToolResult result = await ExecuteWithConfigAsync ( config , "{\" entity\" : \" Book\" , \" function\" : \" count\" , \" field\" : \" *\" }" ) ;
11095
11196 Assert . IsTrue ( result . IsError == true ) ;
11297 JsonElement content = ParseContent ( result ) ;
@@ -117,75 +102,28 @@ public async Task AggregateRecords_DisabledAtEntityLevel_ReturnsToolDisabledErro
117102
118103 #region Input Validation Tests
119104
120- [ TestMethod ]
121- public async Task AggregateRecords_NullArguments_ReturnsInvalidArguments ( )
105+ [ DataTestMethod ]
106+ [ DataRow ( null , null , DisplayName = "Null arguments return InvalidArguments" ) ]
107+ [ DataRow ( "{\" function\" : \" count\" , \" field\" : \" *\" }" , null , DisplayName = "Missing entity returns InvalidArguments" ) ]
108+ [ DataRow ( "{\" entity\" : \" Book\" , \" field\" : \" *\" }" , null , DisplayName = "Missing function returns InvalidArguments" ) ]
109+ [ DataRow ( "{\" entity\" : \" Book\" , \" function\" : \" count\" }" , null , DisplayName = "Missing field returns InvalidArguments" ) ]
110+ [ DataRow ( "{\" entity\" : \" Book\" , \" function\" : \" median\" , \" field\" : \" price\" }" , "median" , DisplayName = "Invalid function returns InvalidArguments" ) ]
111+ [ DataRow ( "{\" entity\" : \" Book\" , \" function\" : \" count\" , \" field\" : \" *\" , \" having\" : { \" between\" : 10 }}" , "Unsupported having operator" , DisplayName = "Unsupported having operator returns InvalidArguments" ) ]
112+ [ DataRow ( "{\" entity\" : \" Book\" , \" function\" : \" count\" , \" field\" : \" *\" , \" having\" : { \" eq\" : \" 10\" }}" , "must be a numeric value" , DisplayName = "Non-numeric having value returns InvalidArguments" ) ]
113+ [ DataRow ( "{\" entity\" : \" Book\" , \" function\" : \" count\" , \" field\" : \" *\" , \" having\" : { \" in\" : [1, \" x\" ] }}" , "must contain only numeric values" , DisplayName = "Non-numeric having.in value returns InvalidArguments" ) ]
114+ public async Task AggregateRecords_InvalidArguments_ReturnInvalidArguments ( string ? argsJson , string ? expectedMessageFragment )
122115 {
123116 RuntimeConfig config = CreateConfig ( ) ;
124- IServiceProvider sp = CreateServiceProvider ( config ) ;
125- AggregateRecordsTool tool = new ( ) ;
117+ CallToolResult result = await ExecuteWithConfigAsync ( config , argsJson ) ;
126118
127- CallToolResult result = await tool . ExecuteAsync ( null , sp , CancellationToken . None ) ;
128- Assert . IsTrue ( result . IsError == true ) ;
129- JsonElement content = ParseContent ( result ) ;
130- Assert . IsTrue ( content . TryGetProperty ( "error" , out JsonElement error ) ) ;
131- Assert . AreEqual ( "InvalidArguments" , error . GetProperty ( "type" ) . GetString ( ) ) ;
132- }
133-
134- [ TestMethod ]
135- public async Task AggregateRecords_MissingEntity_ReturnsInvalidArguments ( )
136- {
137- RuntimeConfig config = CreateConfig ( ) ;
138- IServiceProvider sp = CreateServiceProvider ( config ) ;
139- AggregateRecordsTool tool = new ( ) ;
140-
141- JsonDocument args = JsonDocument . Parse ( "{\" function\" : \" count\" , \" field\" : \" *\" }" ) ;
142- CallToolResult result = await tool . ExecuteAsync ( args , sp , CancellationToken . None ) ;
143119 Assert . IsTrue ( result . IsError == true ) ;
144120 JsonElement content = ParseContent ( result ) ;
145121 Assert . AreEqual ( "InvalidArguments" , content . GetProperty ( "error" ) . GetProperty ( "type" ) . GetString ( ) ) ;
146- }
147122
148- [ TestMethod ]
149- public async Task AggregateRecords_MissingFunction_ReturnsInvalidArguments ( )
150- {
151- RuntimeConfig config = CreateConfig ( ) ;
152- IServiceProvider sp = CreateServiceProvider ( config ) ;
153- AggregateRecordsTool tool = new ( ) ;
154-
155- JsonDocument args = JsonDocument . Parse ( "{\" entity\" : \" Book\" , \" field\" : \" *\" }" ) ;
156- CallToolResult result = await tool . ExecuteAsync ( args , sp , CancellationToken . None ) ;
157- Assert . IsTrue ( result . IsError == true ) ;
158- JsonElement content = ParseContent ( result ) ;
159- Assert . AreEqual ( "InvalidArguments" , content . GetProperty ( "error" ) . GetProperty ( "type" ) . GetString ( ) ) ;
160- }
161-
162- [ TestMethod ]
163- public async Task AggregateRecords_MissingField_ReturnsInvalidArguments ( )
164- {
165- RuntimeConfig config = CreateConfig ( ) ;
166- IServiceProvider sp = CreateServiceProvider ( config ) ;
167- AggregateRecordsTool tool = new ( ) ;
168-
169- JsonDocument args = JsonDocument . Parse ( "{\" entity\" : \" Book\" , \" function\" : \" count\" }" ) ;
170- CallToolResult result = await tool . ExecuteAsync ( args , sp , CancellationToken . None ) ;
171- Assert . IsTrue ( result . IsError == true ) ;
172- JsonElement content = ParseContent ( result ) ;
173- Assert . AreEqual ( "InvalidArguments" , content . GetProperty ( "error" ) . GetProperty ( "type" ) . GetString ( ) ) ;
174- }
175-
176- [ TestMethod ]
177- public async Task AggregateRecords_InvalidFunction_ReturnsInvalidArguments ( )
178- {
179- RuntimeConfig config = CreateConfig ( ) ;
180- IServiceProvider sp = CreateServiceProvider ( config ) ;
181- AggregateRecordsTool tool = new ( ) ;
182-
183- JsonDocument args = JsonDocument . Parse ( "{\" entity\" : \" Book\" , \" function\" : \" median\" , \" field\" : \" price\" }" ) ;
184- CallToolResult result = await tool . ExecuteAsync ( args , sp , CancellationToken . None ) ;
185- Assert . IsTrue ( result . IsError == true ) ;
186- JsonElement content = ParseContent ( result ) ;
187- Assert . AreEqual ( "InvalidArguments" , content . GetProperty ( "error" ) . GetProperty ( "type" ) . GetString ( ) ) ;
188- Assert . IsTrue ( content . GetProperty ( "error" ) . GetProperty ( "message" ) . GetString ( ) ! . Contains ( "median" ) ) ;
123+ if ( ! string . IsNullOrWhiteSpace ( expectedMessageFragment ) )
124+ {
125+ Assert . IsTrue ( content . GetProperty ( "error" ) . GetProperty ( "message" ) . GetString ( ) ! . Contains ( expectedMessageFragment ) ) ;
126+ }
189127 }
190128
191129 #endregion
@@ -1194,6 +1132,14 @@ private static JsonElement ParseContent(CallToolResult result)
11941132 return JsonDocument . Parse ( firstContent . Text ) . RootElement ;
11951133 }
11961134
1135+ private static async Task < CallToolResult > ExecuteWithConfigAsync ( RuntimeConfig config , string ? argsJson , CancellationToken cancellationToken = default )
1136+ {
1137+ IServiceProvider serviceProvider = CreateServiceProvider ( config ) ;
1138+ AggregateRecordsTool tool = new ( ) ;
1139+ JsonDocument ? args = argsJson is null ? null : JsonDocument . Parse ( argsJson ) ;
1140+ return await tool . ExecuteAsync ( args , serviceProvider , cancellationToken ) ;
1141+ }
1142+
11971143 private static void AssertToolDisabledError ( JsonElement content )
11981144 {
11991145 Assert . IsTrue ( content . TryGetProperty ( "error" , out JsonElement error ) ) ;
0 commit comments