@@ -6,19 +6,14 @@ namespace Bunit.Web.Stubs;
66
77internal static class AttributeLineGenerator
88{
9- private const string CascadingParameterAttributeQualifier = "Microsoft.AspNetCore.Components.CascadingParameterAttribute" ;
10- private const string ParameterAttributeQualifier = "Microsoft.AspNetCore.Components.ParameterAttribute" ;
11-
129 public static string GetAttributeLine ( ISymbol member )
1310 {
14- var attribute = member . GetAttributes ( ) . First ( attr =>
15- attr . AttributeClass ? . ToDisplayString ( ) == ParameterAttributeQualifier ||
16- attr . AttributeClass ? . ToDisplayString ( ) == CascadingParameterAttributeQualifier ) ;
11+ var attribute = member . GetAttributes ( ) . First ( SupportedAttributes . IsSupportedAttribute ) ;
1712
1813 var attributeLine = new StringBuilder ( "\t [" ) ;
19- if ( attribute . AttributeClass ? . ToDisplayString ( ) == ParameterAttributeQualifier )
14+ if ( attribute . AttributeClass ? . ToDisplayString ( ) == SupportedAttributes . ParameterAttributeQualifier )
2015 {
21- attributeLine . Append ( $ "global::{ ParameterAttributeQualifier } ") ;
16+ attributeLine . Append ( $ "global::{ SupportedAttributes . ParameterAttributeQualifier } ") ;
2217 var captureUnmatchedValuesArg = attribute . NamedArguments
2318 . FirstOrDefault ( arg => arg . Key == "CaptureUnmatchedValues" ) . Value ;
2419 if ( captureUnmatchedValuesArg . Value is bool captureUnmatchedValues )
@@ -27,9 +22,41 @@ public static string GetAttributeLine(ISymbol member)
2722 attributeLine . Append ( $ "(CaptureUnmatchedValues = { captureString } )") ;
2823 }
2924 }
30- else if ( attribute . AttributeClass ? . ToDisplayString ( ) == CascadingParameterAttributeQualifier )
25+ else if ( attribute . AttributeClass ? . ToDisplayString ( ) == SupportedAttributes . CascadingParameterAttributeQualifier )
26+ {
27+ attributeLine . Append ( $ "global::{ SupportedAttributes . CascadingParameterAttributeQualifier } ") ;
28+ var nameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "Name" ) . Value ;
29+ if ( ! nameArg . IsNull )
30+ {
31+ attributeLine . Append ( $ "(Name = \" { nameArg . Value } \" )") ;
32+ }
33+ }
34+ else if ( attribute . AttributeClass ? . ToDisplayString ( ) == SupportedAttributes . SupplyParameterFromQueryAttributeQualifier )
35+ {
36+ attributeLine . Append ( $ "global::{ SupportedAttributes . SupplyParameterFromQueryAttributeQualifier } ") ;
37+ var nameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "Name" ) . Value ;
38+ if ( ! nameArg . IsNull )
39+ {
40+ attributeLine . Append ( $ "(Name = \" { nameArg . Value } \" )") ;
41+ }
42+ }
43+ else if ( attribute . AttributeClass ? . ToDisplayString ( ) == SupportedAttributes . SupplyParameterFromFormAttributeQualifier )
44+ {
45+ attributeLine . Append ( $ "global::{ SupportedAttributes . SupplyParameterFromFormAttributeQualifier } ") ;
46+ var nameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "Name" ) . Value ;
47+ if ( ! nameArg . IsNull )
48+ {
49+ attributeLine . Append ( $ "(Name = \" { nameArg . Value } \" )") ;
50+ }
51+ var formNameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "FormName" ) . Value ;
52+ if ( ! formNameArg . IsNull )
53+ {
54+ attributeLine . Append ( $ ", (FormName = \" { formNameArg . Value } \" )") ;
55+ }
56+ }
57+ else if ( attribute . AttributeClass ? . ToDisplayString ( ) == SupportedAttributes . SupplyParameterFromQueryAttributeQualifier )
3158 {
32- attributeLine . Append ( $ "global::{ CascadingParameterAttributeQualifier } ") ;
59+ attributeLine . Append ( $ "global::{ SupportedAttributes . SupplyParameterFromQueryAttributeQualifier } ") ;
3360 var nameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "Name" ) . Value ;
3461 if ( ! nameArg . IsNull )
3562 {
0 commit comments