title: Unit Test for n tier architecture
body: <p>I am using 3 tier architecture: Controller, Business, and Data Layer. In my Data Layer, I am making a call to an Sql Server Database by passing Connection String and other necessary parameters.</p>
  
  <p>I have to write unit tests for the Controller layer and Business layer. I want to write a stub (fake repository) from which I would return the hard coded values/result.  When I write a test for business layer, the logic should call this stub instead of the real database.</p>
  
  <p>How can I write the code in the business layer to achieve this?</p>
  
  <p>Business Layer:</p>
  
  <pre><code>public string GetValues(string xmlData)
  {
      DataObject do = new DataObject ();
      string result = do.GetValues(xmlData);
      return result;
  }
  </code></pre>
  
  <p>Data access:</p>
  
  <pre><code>public static string GetValues(string xmlData)
  {
      return SqlHelper.ExecuteScalar(
          ConfigurationManager.AppSettings["ConnectionString"].ToString(),     
          "DBO.usp_GetDetail",
          xmlData
      ).ToString();
  }
  </code></pre>