-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: Use records for stub-generators * refactor: Avoid ISymbols due to caching * refactor: Centralize attribute generator
- Loading branch information
1 parent
5f64044
commit 604e98d
Showing
5 changed files
with
157 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 0 additions & 87 deletions
87
src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/StubComponentBuilder.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Bunit.Web.Stubs; | ||
|
||
internal static class AttributeLineGenerator | ||
{ | ||
private const string CascadingParameterAttributeQualifier = "Microsoft.AspNetCore.Components.CascadingParameterAttribute"; | ||
private const string ParameterAttributeQualifier = "Microsoft.AspNetCore.Components.ParameterAttribute"; | ||
|
||
public static string GetAttributeLine(ISymbol member) | ||
{ | ||
var attribute = member.GetAttributes().First(attr => | ||
attr.AttributeClass?.ToDisplayString() == ParameterAttributeQualifier || | ||
attr.AttributeClass?.ToDisplayString() == CascadingParameterAttributeQualifier); | ||
|
||
var attributeLine = new StringBuilder("\t["); | ||
if (attribute.AttributeClass?.ToDisplayString() == ParameterAttributeQualifier) | ||
{ | ||
attributeLine.Append($"global::{ParameterAttributeQualifier}"); | ||
var captureUnmatchedValuesArg = attribute.NamedArguments | ||
.FirstOrDefault(arg => arg.Key == "CaptureUnmatchedValues").Value; | ||
if (captureUnmatchedValuesArg.Value is bool captureUnmatchedValues) | ||
{ | ||
var captureString = captureUnmatchedValues ? "true" : "false"; | ||
attributeLine.Append($"(CaptureUnmatchedValues = {captureString})"); | ||
} | ||
} | ||
else if (attribute.AttributeClass?.ToDisplayString() == CascadingParameterAttributeQualifier) | ||
{ | ||
attributeLine.Append($"global::{CascadingParameterAttributeQualifier}"); | ||
var nameArg = attribute.NamedArguments.FirstOrDefault(arg => arg.Key == "Name").Value; | ||
if (!nameArg.IsNull) | ||
{ | ||
attributeLine.Append($"(Name = \"{nameArg.Value}\")"); | ||
} | ||
} | ||
|
||
attributeLine.Append("]"); | ||
return attributeLine.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.