What's the best way to use different SQL commands for unit testing only?
<p>I have a .NET project that uses NHibernate. Due to some project requirements, a very specific section of code uses HQL to select a random record using "order by newid()". However, for unit test purposes, I'm using an in-memory SQLite database, which of course chokes on newid(). I need to have this method use an alternate SQLite compatible query only when run from the unit test. I can't add conditional compilation constants only for unit test purposes, and #define only works at the file level, so I can't simply add a constant there either.</p>

<p>I really don't want to have to muck up my repository class with some junk code just to enable this unit test. What are my options?</p>

<p>Edit:</p>

<p>I already have a global class for other stuff, so I added a static TestMode property to it which will be false any time other than when I explicitly set it in my unit test, so the code now looks like:</p>

<pre><code>string random, update;
if (Globals.TestMode)
{
    random = "from Customer order by random()";
}
else
{
    random = "from Customer order by newid()";
}
</code></pre>

<p>This works, but I'd hoped to avoid exactly such an if statement. Still looking for suggestions.</p>
