EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Allow the Unit Testing/Fake db context to be generated in a separate file

Open agentKnipe opened this issue 6 years ago • 5 comments

This could be a quirk of my particular environment, but being able to generate the fake db context into a separate would allow us to effectively hide the unit testing classes from the checked in code that is ultimately built in ci.

The motivation for this is a library that I am working on is almost ready to go into production and Id rather not have the fake db context in my released library.

If there is a better way to handle this situation, please let me know!

agentKnipe avatar Jan 24 '20 17:01 agentKnipe

How about you modify the template to put #if DEBUG {}

#if DEBUG
public class Fake...
{
}
#endif

around the Fake classes?

sjh37 avatar Jan 24 '20 18:01 sjh37

I considered that, but the next time I saved the tt file it would have wiped it out.

agentKnipe avatar Jan 24 '20 19:01 agentKnipe

You could add that to the template, so every time you generate, its there. Approx line 16835 you should find public override string FakeDatabaseContext(). At this location it's for EfCore. Add your #if statement here and at the bottom of the string (approx 17004).

Do the same for FakeDbSet() which is just below it.

sjh37 avatar Jan 27 '20 10:01 sjh37

I'll add a new Settings option to wrap the Fake* classes in a #if statement.

sjh37 avatar Jan 27 '20 10:01 sjh37

Thanks! ill go have a look at the template file and make the changes.

agentKnipe avatar Jan 29 '20 14:01 agentKnipe