【发布时间】:2012-05-01 07:49:37
【问题描述】:
我有一个类 (Not (DAL)),它从 DB 中获取数据并以所需的格式(以特定的类格式)提供给我。
现在我需要编写一个单元测试用例,但 TestContext 数据行总是返回单行。
我想用我的存储过程填充 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] 是存储过程的名称
-
我在等你的回复
标签: unit-testing mstest data-driven-tests