public void GetLongestServingEmployees() { Employee e1 = new Employee { HireDate = new DateTime(2003, 1, 1) }; Employee e2 = new Employee { HireDate = new DateTime(2001, 1, 1) }; Employee e3 = new Employee { HireDate = new DateTime(2000, 1, 1) }; Employee e4 = new Employee { HireDate = new DateTime(2002, 1, 1) }; // The following employee verifies GetLongestServingEmployees does not return terminated employees Employee e5 = new Employee { HireDate = new DateTime(1999, 1, 1), TerminationDate = DateTime.Today }; using (FakeEmployeeContext ctx = new FakeEmployeeContext(new Employee[] { e1, e2, e3, e4, e5 }, new Department[] { })) { EmployeeRepository rep = new EmployeeRepository(ctx); // Select a subset List<Employee> result = rep.GetLongestServingEmployees(2).ToList(); Assert.AreEqual(2, result.Count, "Expected two items in result."); Assert.AreSame(e3, result[0], "Incorrect item at position 0."); Assert.AreSame(e2, result[1], "Incorrect item at position 1."); // Select more than are present result = rep.GetLongestServingEmployees(50).ToList(); Assert.AreEqual(4, result.Count, "Expected four items in result."); } }
public void GetLongestServingEmployees() { Employee e1 = new Employee { HireDate = new DateTime(2003, 1, 1) }; Employee e2 = new Employee { HireDate = new DateTime(2001, 1, 1) }; Employee e3 = new Employee { HireDate = new DateTime(2000, 1, 1) }; Employee e4 = new Employee { HireDate = new DateTime(2002, 1, 1) }; // 以下雇员验证 GetLongestServingEmployees 不返回已离职的雇员。 Employee e5 = new Employee { HireDate = new DateTime(1999, 1, 1), TerminationDate = DateTime.Today }; using (FakeEmployeeContext ctx = new FakeEmployeeContext(new Employee[] { e1, e2, e3, e4, e5 }, new Department[] { })) { EmployeeRepository rep = new EmployeeRepository(ctx); // 选择子集 List<Employee> result = rep.GetLongestServingEmployees(2).ToList(); Assert.AreEqual(2, result.Count, "Expected two items in result."); Assert.AreSame(e3, result[0], "Incorrect item at position 0."); Assert.AreSame(e2, result[1], "Incorrect item at position 1."); // 所选项多于现有项 result = rep.GetLongestServingEmployees(50).ToList(); Assert.AreEqual(4, result.Count, "Expected four items in result."); } }