@@ -6,19 +6,14 @@ namespace Bunit.Web.Stubs;
6
6
7
7
internal static class AttributeLineGenerator
8
8
{
9
- private const string CascadingParameterAttributeQualifier = "Microsoft.AspNetCore.Components.CascadingParameterAttribute" ;
10
- private const string ParameterAttributeQualifier = "Microsoft.AspNetCore.Components.ParameterAttribute" ;
11
-
12
9
public static string GetAttributeLine ( ISymbol member )
13
10
{
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 ) ;
17
12
18
13
var attributeLine = new StringBuilder ( "\t [" ) ;
19
- if ( attribute . AttributeClass ? . ToDisplayString ( ) == ParameterAttributeQualifier )
14
+ if ( attribute . AttributeClass ? . ToDisplayString ( ) == SupportedAttributes . ParameterAttributeQualifier )
20
15
{
21
- attributeLine . Append ( $ "global::{ ParameterAttributeQualifier } ") ;
16
+ attributeLine . Append ( $ "global::{ SupportedAttributes . ParameterAttributeQualifier } ") ;
22
17
var captureUnmatchedValuesArg = attribute . NamedArguments
23
18
. FirstOrDefault ( arg => arg . Key == "CaptureUnmatchedValues" ) . Value ;
24
19
if ( captureUnmatchedValuesArg . Value is bool captureUnmatchedValues )
@@ -27,9 +22,41 @@ public static string GetAttributeLine(ISymbol member)
27
22
attributeLine . Append ( $ "(CaptureUnmatchedValues = { captureString } )") ;
28
23
}
29
24
}
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 )
31
58
{
32
- attributeLine . Append ( $ "global::{ CascadingParameterAttributeQualifier } ") ;
59
+ attributeLine . Append ( $ "global::{ SupportedAttributes . SupplyParameterFromQueryAttributeQualifier } ") ;
33
60
var nameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "Name" ) . Value ;
34
61
if ( ! nameArg . IsNull )
35
62
{
0 commit comments