I have a class with properties in it that are populated via a loader class. Quick example:
class Employee : IEmployee
{
public string EmpFirstName {get; set}
public string EmpLastName {get; set}
}
public class EmpLoader(int employeeID)
{
public void Load(IEmployee emp)
{
emp.EmpFirstName = //lookup the employee using the EmployeeID
//...
}
}
I’m wondering how to go about arranging things so that a mocked EmpLoader‘s Load() method fills in particular values in the Employee. Something like:
Employee myEmp = new Employee();
_empLoader = new Mock<EmpLoader>();
_empLoader.Setup(empL => empL.Load(myEmp)).Sets_myEmp_Properties_Somehow();
I’ve used Moq’s Setup() method before when deciding what sort of return values come back, but wasn’t sure if I can use it or another method to set properties in one class via a third party class. Could be I’m way off here; I’m not an expert in Moq and am open to suggestions.
You can use the Callback() method on the Setup() to load the data: