@@ -480,4 +480,104 @@ public void BaseTypes_Should_BeDeserializedCorrectly()
480480 types [ 0 ] . BaseTypes . ShouldContain ( "Pitstop.Infrastructure.Messaging.Event" ) ;
481481 types [ 0 ] . BaseTypes . ShouldContain ( "System.Object" ) ;
482482 }
483+
484+ [ TestMethod ]
485+ public void MethodParameters_Should_BeDeserializedCorrectly ( )
486+ {
487+ // Assign
488+ var json =
489+ """
490+ [{
491+ "FullName": "Pitstop.Application.CustomerManagementAPI.Controllers.CustomersController",
492+ "BaseTypes": [
493+ "Microsoft.AspNetCore.Mvc.Controller"
494+ ],
495+ "Modifiers": 2,
496+ "Methods": [{
497+ "Parameters": [{
498+ "Type": "Pitstop.CustomerManagementAPI.Commands.RegisterCustomer",
499+ "Name": "command",
500+ "Attributes": [{
501+ "Type": "Microsoft.AspNetCore.Mvc.FromBodyAttribute",
502+ "Name": "FromBody"
503+ }]
504+ }],
505+ "Name": "RegisterAsync",
506+ "Modifiers": 258,
507+ "Attributes": [{
508+ "Type": "Microsoft.AspNetCore.Mvc.HttpPostAttribute",
509+ "Name": "HttpPost"
510+ }]
511+ }]
512+ }]
513+ """ ;
514+
515+ // Act
516+ var types = JsonSerializer . Deserialize < List < TypeDescription > > ( json , JsonDefaults . DeserializerOptions ( ) ) ! ;
517+
518+ // Assert
519+ types . Count . ShouldBe ( 1 ) ;
520+ types [ 0 ] . Methods . Count . ShouldBe ( 1 ) ;
521+
522+ var method = types [ 0 ] . Methods [ 0 ] ;
523+ method . Name . ShouldBe ( "RegisterAsync" ) ;
524+ method . Parameters . Count . ShouldBe ( 1 ) ;
525+
526+ var parameter = method . Parameters [ 0 ] ;
527+ parameter . Type . ShouldBe ( "Pitstop.CustomerManagementAPI.Commands.RegisterCustomer" ) ;
528+ parameter . Name . ShouldBe ( "command" ) ;
529+ parameter . Attributes . Count . ShouldBe ( 1 ) ;
530+
531+ var parameterAttribute = parameter . Attributes [ 0 ] ;
532+ parameterAttribute . Type . ShouldBe ( "Microsoft.AspNetCore.Mvc.FromBodyAttribute" ) ;
533+ parameterAttribute . Name . ShouldBe ( "FromBody" ) ;
534+ }
535+
536+ [ TestMethod ]
537+ public void ConstructorParameters_Should_BeDeserializedCorrectly ( )
538+ {
539+ // Assign
540+ var json =
541+ """
542+ [{
543+ "FullName": "Test.Class",
544+ "Constructors": [{
545+ "Name": "Test",
546+ "Parameters": [{
547+ "Type": "string",
548+ "Name": "name",
549+ "Attributes": [{
550+ "Type": "System.ComponentModel.DataAnnotations.RequiredAttribute",
551+ "Name": "Required"
552+ }]
553+ }, {
554+ "Type": "int",
555+ "Name": "value"
556+ }]
557+ }]
558+ }]
559+ """ ;
560+
561+ // Act
562+ var types = JsonSerializer . Deserialize < List < TypeDescription > > ( json , JsonDefaults . DeserializerOptions ( ) ) ! ;
563+
564+ // Assert
565+ types . Count . ShouldBe ( 1 ) ;
566+ types [ 0 ] . Constructors . Count . ShouldBe ( 1 ) ;
567+
568+ var constructor = types [ 0 ] . Constructors [ 0 ] ;
569+ constructor . Name . ShouldBe ( "Test" ) ;
570+ constructor . Parameters . Count . ShouldBe ( 2 ) ;
571+
572+ var firstParameter = constructor . Parameters [ 0 ] ;
573+ firstParameter . Type . ShouldBe ( "string" ) ;
574+ firstParameter . Name . ShouldBe ( "name" ) ;
575+ firstParameter . Attributes . Count . ShouldBe ( 1 ) ;
576+ firstParameter . Attributes [ 0 ] . Type . ShouldBe ( "System.ComponentModel.DataAnnotations.RequiredAttribute" ) ;
577+
578+ var secondParameter = constructor . Parameters [ 1 ] ;
579+ secondParameter . Type . ShouldBe ( "int" ) ;
580+ secondParameter . Name . ShouldBe ( "value" ) ;
581+ secondParameter . Attributes . Count . ShouldBe ( 0 ) ;
582+ }
483583}
0 commit comments