我有以下方法,并希望通过DataReader为映射结果编写单元测试用例。Hot编写使用Moq的SqlDataReader的单元测试用例
public interface IIMGAdvancedSearchDBProvider
{
clsGPAdvancedSearchResult GetSearchResult(clsIMGAdvancedImageSearchCriteria searchCriteria);
}
public class clsIMGAdvancedSearchSQLDBProvider : IIMGAdvancedSearchDBProvider
{
public clsGLGJSearchResultItem GetSearchResult(clsIMGAdvancedImageSearchCriteria searchCriteria)
{
using (var sqlConnection = DfxDbConnection)
{
using (var sqlCommand = sqlConnection.CreateCommand())
{
sqlCommand.Parameters.Add("@userKey", SqlDbType.UniqueIdentifier).Value = State.WebUserKey;
sqlCommand.Parameters.Add("@SiteCode", SqlDbType.VarChar).Value = State.SiteCode;
sqlCommand.Parameters.Add("@MaxRows", SqlDbType.Int).Value = searchCriteria.MaxRows;
//Add required client, client group filter paramters
AddClientAndClientGroupFilterParameters(searchCriteria, sqlCommand);
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = GetCompleteSQLStatement(searchCriteria);
var reader = sqlCommand.ExecuteReader();
return alTransaction(reader);
reader.Close();
}
}
return null;
}
private clsGLGJSearchResultItem GetJournalTransaction(SqlDataReader reader)
{
return new clsGLGJSearchResultItem
{
ClientKey = DfxUtilities.GetGuidValueFromReader(reader, "ClientKey") ?? Guid.Empty,
JournalId = DfxUtilities.GetLongValueFromReader(reader, "JournalID") ?? 0,
AccountingDate = (DateTime)reader["Date"],
JournalSource =
(enumJournalSources)
Enum.Parse(typeof(enumJournalSources), reader["Source"].ToString()),
Description = DfxUtilities.GetStringValueFromReader(reader, "Description"),
DebitAmount = DfxUtilities.GetDecimalValueFromReader(reader, "DebitAmount") ?? 0,
CreditAmount = DfxUtilities.GetDecimalValueFromReader(reader, "CreditAmount") ?? 0,
ClientCode = DfxUtilities.GetStringValueFromReader(reader, "ClientCode"),
ClientName = DfxUtilities.GetStringValueFromReader(reader, "ClientName"),
Images = GetImageItems(reader)
};
}
}
任何人都可以帮我解决这个问题吗?
你想解决什么问题? –
我想为SqlDataReader映射编写测试用例。 – Sharad
SO不是您的分包商。如果您有关于您撰写的测试的具体问题,或者对如何测试相关代码所做的研究有疑问,那么这些问题可能与主题有关。 –