我有UpdateEmployees()
方法更新所有员工数据。
在为该方法编写单元测试时,它不会覆盖OrderBy()
语句。如何获得order by语句的代码覆盖率。
我使用过Moq单元测试。
//This Method returns list of employee
Public void UpdateEmployees()
{
var employees = _repository.GetAllEmployees().OrderBy(x => x.Name);
// Some Update operations below.
}
//Unit Test for GetAllEmployee Method.
Public void UnitTest()
{
var employees = new Fixture.Build<Employee>().Createmany(5).ToList();
var moqRepository = new Mock<IRepository>(MockBehavior.Strict);
moqRepository.Setup(r => r.GetAllEmployees()).Returns(employees)
var employee = new Employee(moqRepositort.Object);
employee.UpdateEmployees();
}
答案 0 :(得分:0)
如果将List枚举为List:
,它将被覆盖var employees = _repository.GetAllEmployees().OrderBy(x => x.Name).ToList();