如何为委托方法编写测试? 要么 谨防2个打开的连接,并将'hooks'放在同一个SQL表上....
这不是直接诊断,测试和证明我的当前解决方案不是问题。
我怎么能让TDD或写入的单元/集成测试陷入困境?重新设计建议......
委托方法:
这是委托方法:
public int Update(int transferID)
{
var obj = new TransferWebMessage();
using (SqlConnection conn = base.GetNewConnection())
{
using (SqlCommand sp_cmd = new SqlCommand())
{
sp_cmd.CommandText = "TransferWebTransmitUpdate";
sp_cmd.CommandType = CommandType.StoredProcedure;
sp_cmd.Parameters.AddWithValue("TransferID", transferID);
sp_cmd.Connection = conn;
conn.Open();
SqlDataReader rdr = sp_cmd.ExecuteReader();
int roweffected;
while (rdr.Read())
{
roweffected = rdr.GetInt32(0),
}
}
}
return roweffected;
}
这是调用行来处理并调用委托:
public void WatchForDataTransferRequests(_delegateMethod callback)
{
using (SqlConnection conn = new SqlConnection(_insol_SubscriberConnectionString))
{
// Construct the command to get any new ProductReview rows from the database along with the corresponding product name
// from the Product table.
SqlCommand cmd = new SqlCommand(
"SELECT [TransferID]" +
" FROM [dbo].[TransferWebTransmit]" +
" ORDER BY [TransferID] ASC", conn);
cmd.Parameters.Add("@CurrentTransferID", SqlDbType.Int);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
// Process the rows
while (rdr.Read())
{
Int32 transferID = (Int32)rdr.GetInt32(0);
callback(transferID);
}
}
}