Closed tomasKosar closed 11 months ago
https://github.com/RandomEngy/UnitTestBoilerplateGenerator/blob/master/src/Services/TestGenerationService.cs
CollectTestGenerationContextAsync
is what you want to modify here. That's the code that examines the class and finds what types it needs as constructor arguments, and populates ConstructorTypes
on the TestGenerationContext
. It uses Roslyn APIs to check the syntax tree.
The syntax tree visualizer is a good tool to figure out what to look for when examining the class: https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/syntax-visualizer?tabs=csharp
One caveat here is that to provide compatibility with VS 2019, we reference the v1 Microsoft.CodeAnalysis NuGet packages, which means you don't have the actual enum values like SyntaxKind.RecordDeclaration
. You have to use the raw numbers that correspond to those syntax types.
To develop you need to install the VS Extension development capability, then you can just F5 and open Sandbox.sln to test.
OK Thanks for pointing me to the right direction.
I think I figured what changes we need to make to implement this. I have them locally and it seems to be working. Its just that I do not have write access for this repo so I am not allowed to push a branch with those changes. I am happy to share them here or push the branch if I would get access.
You can create a pull request to submit your changes.
Basically: fork this repository, make a new branch with your changes on it, then visit the repository on GitHub and it will prompt you to start a pull request.
PR can be found here #37
Resolved by PR #37
Installed product versions
Description
Fields declarations and fields initialisation does not work when primary constructor is used instead of traditional constructor.
Steps to recreate
Current behavior
Fields declarations and fields initialisation are not created when primary constructor is used.
Expected behavior
Fields declarations and fields initialisation are created when primary constructor is used.
Notes
If I convert class from primary constructor to traditional constructor then everything works as expected. This could very well be because this is relatively new C# feature and obviously this extension could not anticipate this. https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12#primary-constructors I very much like this extension and I appreciate all the work on this. If anyone can point me to how to solve this or implement this functionality then it would be appreciated. I understand that with Copilot there are other ways how to quickly generate unit tests boiler plate but I still do see this extension as a big help.