raz*_*p26 5 c# wcf unit-testing entity-framework
我是Unit Tests的新手,所以我一直在尝试编写一些示例来学习使用它们的正确方法.我有一个示例项目,它使用Entity Framework连接到数据库.
我正在使用由数据访问层组成的n层体系结构,该数据访问层使用EF查询数据库,业务层调用数据访问层方法来查询数据库并使用检索到的数据执行其业务目的以及组成的服务层简单地调用业务层对象的WCF服务.
我是否必须为每一层(数据访问,业务层,服务层?)编写单元测试?
哪种方法可以为查询数据库的方法编写单元测试代码?下一个代码是我的数据访问层中的一个方法的例子,它对数据库执行选择,它的单元测试应该如何?
public class DLEmployee
{
private string _strErrorMessage = string.Empty;
private bool _blnResult = true;
public string strErrorMessage
{
get
{
return _strErrorMessage;
}
}
public bool blnResult
{
get
{
return _blnResult;
}
}
public Employee GetEmployee(int pintId)
{
Employee employee = null;
_blnResult = true;
_strErrorMessage = string.Empty;
try
{
using (var context = new AdventureWorks2012Entities())
{
employee = context.Employees.Where(e => e.BusinessEntityID == pintId).FirstOrDefault();
}
}
catch (Exception ex)
{
_strErrorMessage = ex.Message;
_blnResult = false;
}
return employee;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1242 次 |
| 最近记录: |