Open JoanComasFdz opened 2 years ago
The attributes (+ assembly) should be removed from the built projects due to the conditional attribute on them..
I was more thinking of doing something completely different and only in the test project like
[assemby: GenerateDataBuilder(typeof(Model))]
or
[GenerateDataBuilder(typeof(Customer))]
public partial class Builders
{
public static CustomerBuilder DefaultCustomer => Builders.Customer.WithName("foo").WithAddress(...);
}
That also has the added benefit of being able to look at the metadata of the referenced assembly instead of the syntactic/semantic models of the code being built to generate the code, that could benefit from Roslyn 4's incremental generator feature
So I am trying to follow that same approach where a nuget is added to a unit testing project and it automatically generates whatever files are needed, in this repo:
https://github.com/JoanComasFdz/dotnet-scenario-unittesting
I am analyzing the referenced projects, looking for types and generating some files for them.
Unfortunately, this doesn't seem to be working for xUnit projects: https://github.com/dotnet/roslyn-sdk/issues/972#
Right now the builders are created in the same project where the decorated classes live in.
Given that the Attributes and the SourceGenerator and already split in two NuGet packages, I would like to be able to decorate the classes in the production project, but create the Data Builders in the test project.
Example:
TestApp
Person.cs
TestApp.Tests
After building the solution:
TestApp.Tests
PersonBuilder.cs
This way, production code is not polluted with testing code.
Do you have any directions on how to achieve this?