C#RhinoMock嵌套映射表单元测试

时间:2017-04-15 21:01:48

标签: c# unit-testing rhino-mocks

下面是三个表,其中一个是Master表,两个是每个表的关系。在进行单元测试时,我无法根据我的业务逻辑获得少数测试用例场景。

public class Employee
{
    public int ID { get; set; }
    public string Name { get; set; }
    public virtual ICollection<EmployeeDepartment> EmployeeDepartments { get; set; }
}

public class EmployeeDepartment
{
    public int EmployeeID { get; set; }
    public int DepartmentID { get; set; }

    public virtual Department { get; set; }
    public virtual Employee{ get; set; }
}

public class Department
{
    public int ID { get; set; }
    public string DName { get; set; }
    public virtual ICollection<EmployeeDepartment> EmployeeDepartments { get; set; }
}

这是我的单元测试方法代码:

// Arrange
var employees = new FakeDbSet<Employee>();            
Expect.Call(dataContext.Set<Employee>()).Return(employees).Repeat.Any();

// Act
--Code for Service Method

// Assert
var actualEmpl = this.actualEmpl;
Assert.IsTrue(actualEmpl.EmployeeDepartment.Any(w => w.Department.DName == "ABC"));
  

我的问题是我总是得到&#34; w.Department.DName&#34;一片空白。请   帮助我解决问题。

     

部门是主表列表(最少20行)和EmployeeDepartment   只能有一个或几个记录。

0 个答案:

没有答案