title: Test Driven unit testing with stored procedure in VS 2010
body: <p>I have a class (Not (DAL)) that get's data from DB and give it to me in required format(in specific class format).</p>
  
  <p>Now i need to write a unit test case, but TestContext Data row always return me single row.</p>
  
  <p>I want to fill TestContext by my stored procedure. Please tell me how can i specify stored procedure name. 
  Thanks in advance.</p>
  
  <p>Here  Is Code.</p>
  
  <pre><code>public static List&lt;TextValueField&gt; ExternalDataGet(int providerId)
      {
          return ListFactory&lt;TextValueField&gt;.Create(Keys.QAT, "[stats].[GetExternalDataV2]", new object[] { providerId }, TextValueField.Factory);
      }
  public static List&lt;T&gt; Create(string key, string sp, object[] parameters, FactoryDelegate factory)
      {
          List&lt;T&gt; list = new List&lt;T&gt;();
          Database db = DatabaseFactory.CreateDatabase(key);
          string connectionString = db.ConnectionStringWithoutCredentials;
  
          using (DbCommand cmd = db.GetStoredProcCommand(sp, parameters))
          {
              try
              {
                  using (cmd.Connection = db.CreateConnection())
                  {
                      cmd.Connection.Open();
                      cmd.CommandTimeout = 0;
                      using (DbDataReader reader = cmd.ExecuteReader())
                      {
                          try
                          {
                              while (reader.Read())
                                  list.Add(factory(reader));
                          }
                          finally
                          {
                              if (!reader.IsClosed)   
                                  reader.Close();
                          }
                      }
                      cmd.Connection.Close();
                  }
              }
              catch (Exception ex)
              {
                  Debug.WriteLine(ex.Message);
                  throw new DataAccessException(ex, key, connectionString, sp, parameters);
              }
              finally
              {
                  if (cmd.Connection != null)
                      if (cmd.Connection.State == ConnectionState.Open)
                          cmd.Connection.Close();
              }
          }
          return list;
      }
  </code></pre>