title: adjusting constants in static class for unit tests in C#
body: <p>I have a static class representing a connection pool that I want to unit test using Visual Studio 2008's built-in unit testing framework.  The static class has some constants in it, like for the maximum allowed connections.  I want to decrease this value for my unit test so I don't have to have a lot of connections open in order to hit a test condition (specifically, the code for when the maximum allowed connections has been reached).  Is there a way I can edit this constant just in the unit test?  That doesn't seem possible to me.</p>
  
  <p>One solution I have is to write another method for accessing the code to be tested, one that would take 'maximum allowed connections' as a parameter.  That seems slightly dirty in that it modifies the code I want to test, even if only slightly; however, is there a better alternative?  Here's some of my code, for reference:</p>
  
  <pre><code>internal static class ConnectionPool&lt;T&gt; where T : Connection, new()
  {
      private const int MAX_OBJECTS = 25;
      private static int _totalConnections;
  
      internal static T getConnection(bool testMode)
      {
          if (_totalConnections &gt;= MAX_OBJECTS)
          {
              // Here's the code I want to test
          }
      }
  }
  </code></pre>