我有一个类(Not(DAL)),它从数据库获取数据并以所需格式(以特定的类格式)提供给我。在VS 2010中使用存储过程测试驱动的单元测试
现在我需要编写一个单元测试用例,但TestContext Data行总是返回单行。
我想通过我的存储过程来填充TestContext。请告诉我如何指定存储过程名称。 在此先感谢。
这是代码。
public static List<TextValueField> ExternalDataGet(int providerId)
{
return ListFactory<TextValueField>.Create(Keys.QAT, "[stats].[GetExternalDataV2]", new object[] { providerId }, TextValueField.Factory);
}
public static List<T> Create(string key, string sp, object[] parameters, FactoryDelegate factory)
{
List<T> list = new List<T>();
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;
}
如何测试根据提供的参数返回DataSet的方法。请给我一些想法。 –
你可能需要张贴一些代码来澄清你的问题。 –
[stats]。[GetExternalDataV2]是存储过程的名称 –