@@ -150,6 +150,162 @@ public void ItInvalidatesSchemaForNewDefaultValue()
150150 Assert . NotSame ( schema1 , m . Schema ) ;
151151 }
152152
153+ [ Fact ]
154+ public void ItCanBeConstructedWithAllParameters ( )
155+ {
156+ // Test the new constructor that accepts all parameters
157+ var schema = KernelJsonSchema . Parse ( """{ "type": "string", "description": "test schema" }""" ) ;
158+ var m = new KernelParameterMetadata (
159+ name : "testParam" ,
160+ description : "Test parameter description" ,
161+ defaultValue : "defaultVal" ,
162+ isRequired : true ,
163+ parameterType : typeof ( string ) ,
164+ schema : schema ) ;
165+
166+ Assert . Equal ( "testParam" , m . Name ) ;
167+ Assert . Equal ( "Test parameter description" , m . Description ) ;
168+ Assert . Equal ( "defaultVal" , m . DefaultValue ) ;
169+ Assert . True ( m . IsRequired ) ;
170+ Assert . Equal ( typeof ( string ) , m . ParameterType ) ;
171+ Assert . Equal ( JsonSerializer . Serialize ( schema ) , JsonSerializer . Serialize ( m . Schema ) ) ;
172+ }
173+
174+ [ Fact ]
175+ public void ItCanBeConstructedWithAllParametersAndJsonSerializerOptions ( )
176+ {
177+ // Test the new constructor with JsonSerializerOptions
178+ var jsos = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy . CamelCase } ;
179+ var schema = KernelJsonSchema . Parse ( """{ "type": "integer" }""" ) ;
180+ var m = new KernelParameterMetadata (
181+ name : "testParam" ,
182+ description : "Test parameter" ,
183+ defaultValue : 42 ,
184+ isRequired : false ,
185+ parameterType : typeof ( int ) ,
186+ schema : schema ,
187+ jsonSerializerOptions : jsos ) ;
188+
189+ Assert . Equal ( "testParam" , m . Name ) ;
190+ Assert . Equal ( "Test parameter" , m . Description ) ;
191+ Assert . Equal ( 42 , m . DefaultValue ) ;
192+ Assert . False ( m . IsRequired ) ;
193+ Assert . Equal ( typeof ( int ) , m . ParameterType ) ;
194+ Assert . Equal ( JsonSerializer . Serialize ( schema ) , JsonSerializer . Serialize ( m . Schema ) ) ;
195+ }
196+
197+ [ Fact ]
198+ public void ItUsesDefaultValuesInNewConstructor ( )
199+ {
200+ // Test that optional parameters have correct default values
201+ var m = new KernelParameterMetadata ( "testParam" ) ;
202+
203+ Assert . Equal ( "testParam" , m . Name ) ;
204+ Assert . Empty ( m . Description ) ;
205+ Assert . Null ( m . DefaultValue ) ;
206+ Assert . False ( m . IsRequired ) ;
207+ Assert . Null ( m . ParameterType ) ;
208+ Assert . Null ( m . Schema ) ;
209+ }
210+
211+ [ Fact ]
212+ public void ItThrowsForInvalidNameInNewConstructor ( )
213+ {
214+ // Test that the new constructor still validates the name parameter
215+ Assert . Throws < ArgumentNullException > ( ( ) => new KernelParameterMetadata ( null ! , "description" ) ) ;
216+ Assert . Throws < ArgumentException > ( ( ) => new KernelParameterMetadata ( "" , "description" ) ) ;
217+ Assert . Throws < ArgumentException > ( ( ) => new KernelParameterMetadata ( " " , "description" ) ) ;
218+ Assert . Throws < ArgumentException > ( ( ) => new KernelParameterMetadata ( "\t \r \v " , "description" ) ) ;
219+ }
220+
221+ [ Fact ]
222+ public void ItInfersSchemaWhenNotProvidedInNewConstructor ( )
223+ {
224+ // Test that schema is inferred from type when not explicitly provided
225+ var m = new KernelParameterMetadata (
226+ name : "testParam" ,
227+ description : "An integer parameter" ,
228+ parameterType : typeof ( int ) ) ;
229+
230+ Assert . NotNull ( m . Schema ) ;
231+ Assert . Equal ( JsonSerializer . Serialize ( KernelJsonSchema . Parse ( """{"description":"An integer parameter", "type":"integer"}""" ) ) , JsonSerializer . Serialize ( m . Schema ) ) ;
232+ }
233+
234+ [ Fact ]
235+ public void ItIncludesDefaultValueInInferredSchemaFromNewConstructor ( )
236+ {
237+ // Test that default value is included in inferred schema
238+ var m = new KernelParameterMetadata (
239+ name : "testParam" ,
240+ description : "An integer parameter" ,
241+ defaultValue : 100 ,
242+ parameterType : typeof ( int ) ) ;
243+
244+ Assert . NotNull ( m . Schema ) ;
245+ Assert . Equal ( JsonSerializer . Serialize ( KernelJsonSchema . Parse ( """{"description":"An integer parameter (default value: 100)", "type":"integer"}""" ) ) , JsonSerializer . Serialize ( m . Schema ) ) ;
246+ }
247+
248+ [ Fact ]
249+ public void ItHandlesNullDescriptionInNewConstructor ( )
250+ {
251+ // Test that null description is handled correctly
252+ var m = new KernelParameterMetadata (
253+ name : "testParam" ,
254+ description : null ,
255+ defaultValue : "test" ,
256+ isRequired : true ,
257+ parameterType : typeof ( string ) ) ;
258+
259+ Assert . Equal ( "testParam" , m . Name ) ;
260+ Assert . Empty ( m . Description ) ; // null description should become empty string
261+ Assert . Equal ( "test" , m . DefaultValue ) ;
262+ Assert . True ( m . IsRequired ) ;
263+ Assert . Equal ( typeof ( string ) , m . ParameterType ) ;
264+ }
265+
266+ [ Fact ]
267+ public void ItHandlesNullSchemaInNewConstructor ( )
268+ {
269+ // Test that null schema parameter is handled correctly
270+ var m = new KernelParameterMetadata (
271+ name : "testParam" ,
272+ description : "Test param" ,
273+ defaultValue : null ,
274+ isRequired : false ,
275+ parameterType : typeof ( string ) ,
276+ schema : null ) ;
277+
278+ Assert . Equal ( "testParam" , m . Name ) ;
279+ Assert . Equal ( "Test param" , m . Description ) ;
280+ Assert . Null ( m . DefaultValue ) ;
281+ Assert . False ( m . IsRequired ) ;
282+ Assert . Equal ( typeof ( string ) , m . ParameterType ) ;
283+ // Schema should be inferred from type since explicit schema is null
284+ Assert . NotNull ( m . Schema ) ;
285+ }
286+
287+ [ Theory ]
288+ [ ClassData ( typeof ( TestJsonSerializerOptionsForPrimitives ) ) ]
289+ public void ItUsesJsonSerializerOptionsInNewConstructor ( JsonSerializerOptions ? jsos )
290+ {
291+ // Test that JsonSerializerOptions are used correctly in the new constructor
292+ var m = jsos is not null ?
293+ new KernelParameterMetadata (
294+ name : "testParam" ,
295+ description : "Test parameter" ,
296+ parameterType : typeof ( int ) ,
297+ jsonSerializerOptions : jsos ) :
298+ new KernelParameterMetadata (
299+ name : "testParam" ,
300+ description : "Test parameter" ,
301+ parameterType : typeof ( int ) ) ;
302+
303+ Assert . Equal ( "testParam" , m . Name ) ;
304+ Assert . Equal ( "Test parameter" , m . Description ) ;
305+ Assert . Equal ( typeof ( int ) , m . ParameterType ) ;
306+ Assert . Equal ( JsonSerializer . Serialize ( KernelJsonSchema . Parse ( """{"description":"Test parameter", "type":"integer"}""" ) ) , JsonSerializer . Serialize ( m . Schema ) ) ;
307+ }
308+
153309#pragma warning disable CA1812 // class never instantiated
154310 internal sealed class Example
155311 {
0 commit comments