cezarypiatek / MappingGenerator

:arrows_counterclockwise: "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
https://marketplace.visualstudio.com/items?itemName=54748ff9-45fc-43c2-8ec5-cf7912bc3b84.mappinggenerator
MIT License
1.03k stars 120 forks source link

UnitTest generator? #164

Closed dominikjeske closed 3 years ago

dominikjeske commented 3 years ago

Feature description Generate unit test for each property

Reasoning behind This tool is a great time saver for a starting point when writing mappers. It would be nice to have same generator for unit test asserting mapping of each property. For start it seems not important but when we have some logic after generation in the mapper or we would like to protect our code from regression it would be nice to have those tests generated.

Real word example of the usage

public void AssertName()
{
      var source = new SourceObject
      {
              Name = "Test";
      }
      var mapper = new PersonMapper();

      var mapped = mapper.Map(source);

      Assert.Equal("TestChanged", mapped.Name);

}
cezarypiatek commented 3 years ago

Hi @dominikjeske

Honesty, I can't see any value in keeping a separated tests for individual properties. Can you elaborate a little bit more what are the benefits of that approach over having a single test per use case that check all properties? If you need something that could protect your mappings from the regression then I recommend tools like ApprovalTests.Net or Verify. Please let me know if that solve your problem?

If you really need this kind of generator then maybe you can achieve that with my other Visual Studio extension https://github.com/cezarypiatek/CsharpMacros

dominikjeske commented 3 years ago

Sometimes first idea is not ideal ;) I have rethinked this again and it would be over engineering;)