Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Generate unit tests #148

Closed
WojciechNagorski opened this issue Nov 16, 2020 · 3 comments
Closed

Generate unit tests #148

WojciechNagorski opened this issue Nov 16, 2020 · 3 comments

Comments

@WojciechNagorski
Copy link

I know that this issue is a little out of the scope of this project. I've seen #131.

I wanted to change AutoMapper to MappingGenerator but I have one blocker. I have many profiles in my program (the same situation is in many other projects in my company) and I have one unit test that checks the validation of mapping

           foreach (var profile in profiles)
            {
                var mapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile(profile); });
                try
                {
                    mapperConfig.AssertConfigurationIsValid();
                }
                catch (AutoMapperConfigurationException ex)
                {
                    // I know that there is a problem
                }
            }

If someone adds a property to an object, the test will show him an error. I can't reproduce this behavior with MappingGenerator without creating a unit test for each mapping. But it requires a lot of work and the reviewer have to check if the test is added.

So if I have junior devs in my team I prefer to stay with AutoMapper with its disadvantages (I know it is slow, it is hard to debug, IDE doesn't show references of property) but I know that mappings are ok (or it is highly probable)

Any ideas on how to automate it?

@cezarypiatek
Copy link
Owner

I'm not familiar with the profiles (or I don't remember it, because it's been round 6 years since I used AutoMapper the last time). If you want to track unmapped fields then I would recommend trying to use /*FullInitRequired:recursive*/ marker with my other analyzer described here https://cezarypiatek.github.io/post/immutable-types-with-roslyn/ This should solve the problem at least from the target object perspective.

@cezarypiatek
Copy link
Owner

@WojciechNagorski does it answer your question?

@WojciechNagorski
Copy link
Author

Yes, We can close this issue. But I'm not sure if this solution is enough. I need to try it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants