You haven't provided the full method signature of IRepository<T> Find()
, but at a guess, it is something like IQueryable<T> Find()
. Because we want to mock it to return a small amount of fake data, it doesn't really matter that we just bind it to an in memory List. Because the SUT performs a filter (Active
), ensure that you also provide unwanted data in the fake data to ensure that the SUT's filtering logic is working correctly.
Assuming all of this, your setup would look something like:
var newEmpLst = new List<Employee>
{
new Employee()
{
Name = "Jones",
Status = "Active"
},
new Employee()
{
Name = "Smith",
Status = "Inactive"
},
};
mockRep.Setup(repos => repos.Find())
.Returns(newEmpLst.AsQueryable());
Your Act + Assert would then be something like:
var service = new EmployeeService(mockRep.Object);
var createResult = service.GetAllActiveEmployees();
Assert.AreEqual(1, createResult);
Assert.IsTrue(createResult.Any(x => x.Name == "Jones"));
Assert.IsFalse(createResult.Any(x => x.Name == "Smith"));
mockRep.Verify(repos => repos.Find(), Times.Exactly(1));