title: How to make a singleton design testable?
body: <p>Suppose I have the following singleton:</p>
  
  <pre><code>public class ConfigReader
  {
      static readonly ConfigReader instance = new ConfigReader();
  
      private ConfigReader() { }
  
      public static ConfigReader Instance { get { return instance; } }
  
      public int RecordsPerPage
      {
          get 
          { 
              var configPath = DB.Table&lt;ConfigSource&gt;().GetFieldValue("Path").ToString();
              if (configSource == "Database")
                  return Convert.ToInt32(DB.Table&lt;Configuration&gt;().GetFieldValue("RecordsPerPage"));
              else
                  return Convert.ToInt32(ConfigurationManager.AppSettings["RecordsPerPage"]);
          }
      }
  }
  </code></pre>
  
  <p>How can I write a unit test to mock the DB.Table &amp; ConfigurationManager.AppSettings calls within this singleton so that I can test it with unit tests?</p>
  
  <p>Actually this leads to another question for TDD: Do we really necessary to consider the testability when we design the system? Seems not every design can align with the TDD principles, like DI, etc. Did I misunderstand something?</p>