James Huxley
James Huxley

Reputation: 55

Unit test roslyn component

I've seen posts around that essentially come down to "to unit test, parse text A and expect text B". With my component, I've tried to separate the analyser into many parts and I'd like to test individual parts. For example, I have a method that takes a MethodDeclarationSyntax and extracts information from that to pass on to another component that may take a ObjectCreationExpressionSyntax.

For the life of me, I can't figure out how to create a MethodDeclarationSyntax let alone creating one with some hardcoded value that I can use to test various cases.

Upvotes: 0

Views: 257

Answers (1)

SLaks
SLaks

Reputation: 888047

Use the methods in the SyntaxFactory class to create syntax nodes.

Or paste your code into https://roslynquoter.azurewebsites.net/ to generate those calls for you.

Upvotes: 3

Related Questions