Calling InteractiveViews multiple times

Oct 23, 2015 at 4:15 PM

Great little library. I am thinking of using your library for holding generated views, but I would also like to use it in my Unit Tests, as the startup time of EF based tests is really long. The simplest way is to put it in a FixtureSetup (NUnit) method in every test group that uses EF. Problem is, you specifically say it must only be called once.

Is there any way to find out if it has been called before so I can skip calling it?
Oct 29, 2015 at 3:47 AM

If you want to have fast and reliable unit tests you should not make trips to the database at all. Here are some resources about testing EF based applications without hitting the database: ,

EF will initialize views once per database/context. So, if you call the .SetViewCache() method multiple times before views are initialized the last call will win. If you call it after views are initialized then it will effectively be a no-op since once views have already been initialized and EF will not try to re-initialize them.

If your tests are using the same database I don't actually think views will help a whole lot. You might or might not (depending on the model size) shave a little bit of the initial start up time but this is a one time thing per all tests and not per a test or a test suite (views are cached in the AppDomain once initialized and won't be reinitialized until the AppDomain dies). Again, looking how to change tests to not hit the database is IMHO a better ROI.