I have a .NET project that uses NHibernate. Due to some project requirements, a very specific section of the code uses HQL to select a random record using "order by newid ()". However, for unit test purposes, I use an in-memory SQLite database, which of course throttles to newid (). I need this method to use an alternative SQLite-compatible query only when starting from unit test. I cannot add conditional compilation constants for unit test purposes only, and #define works only at the file level, so I cannot just add a constant there.
Actually, I don't want my repository class to be run with some junk email code to enable this unit test. What are my options?
Edit:
I already have a global class for other things, so I added the static TestMode property to it, which will be false at any time, except when I explicitly set it in my unit test, so the code now looks like this:
string random, update; if (Globals.TestMode) { random = "from Customer order by random()"; } else { random = "from Customer order by newid()"; }
This works, but I was hoping to avoid such an if statement. Still looking for suggestions.
Chris source share