Unit testing VS 2010中带有存储过程的测试驱动单元测试

Unit testing VS 2010中带有存储过程的测试驱动单元测试,unit-testing,mstest,data-driven-tests,Unit Testing,Mstest,Data Driven Tests,我有一个类(不是(DAL)),它从DB中获取数据,并以所需的格式(特定的类格式)提供给我 现在我需要编写一个单元测试用例,但TestContext数据行总是返回单行 我想用存储过程填充TestContext。请告诉我如何指定存储过程名称。 提前谢谢 这是代码 public static List<TextValueField> ExternalDataGet(int providerId) { return ListFactory<TextValueFi

我有一个类(不是(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;
    }
公共静态列表ExternalDataGet(int providerId)
{
返回ListFactory.Create(Keys.QAT,“[stats].[GetExternalDataV2]”,新对象[]{providerId},TextValueField.Factory);
}
创建公共静态列表(字符串键、字符串sp、对象[]参数、FactoryDelegate工厂)
{
列表=新列表();
Database db=DatabaseFactory.CreateDatabase(key);
字符串connectionString=db.ConnectionStringWithoutCredentials;
使用(DbCommand cmd=db.GetStoredProcCommand(sp,参数))
{
尝试
{
使用(cmd.Connection=db.CreateConnection())
{
cmd.Connection.Open();
cmd.CommandTimeout=0;
使用(DbDataReader=cmd.ExecuteReader())
{
尝试
{
while(reader.Read())
列表。添加(工厂(读卡器));
}
最后
{
如果(!reader.IsClosed)
reader.Close();
}
}
cmd.Connection.Close();
}
}
捕获(例外情况除外)
{
Debug.WriteLine(例如消息);
抛出新的DataAccessException(例如,键、connectionString、sp、参数);
}
最后
{
if(cmd.Connection!=null)
if(cmd.Connection.State==ConnectionState.Open)
cmd.Connection.Close();
}
}
退货清单;
}
我想用存储过程填充TestContext。请告诉我如何指定存储过程名称

这将处理您的请求

public static List<TextValueField> ExternalDataGet(int providerId, string storedProc = "[stats].[GetExternalDataV2]")
{
    return ListFactory<TextValueField>.Create(Keys.QAT, storedProc, new object[] { providerId }, TextValueField.Factory);
}
公共静态列表ExternalDataGet(int providerId,string storedProc=“[stats].[GetExternalDataV2]”)
{
返回ListFactory.Create(Keys.QAT,storedProc,新对象[]{providerId},TextValueField.Factory);
}

如何测试根据提供的参数返回数据集的方法。请告诉我一些想法。您可能需要发布一些代码来澄清您的问题。[stats].[GetExternalDataV2]是存储过程的名称我正在等待您的响应我正在等待您的响应。@PavanTiwari:响应什么?如果您回答了上述问题,您可以回答。@PavanTiwari:您还没有问任何问题。我如何用存储过程数据的结果填充TestContext