With FakeItEasy, I want to fake an interface method to return some custom list, the method has more than 4 arguments, signature of method is this:
IList<Employee> FindAll(DateTime dateFrom, DateTime dateTill, Guid locationId, Gender gender, int age);
While FakeItEasy has ReturnsLazily method which has supports till only 4 arguments, so for this 5 arguments method I cannot use ReturnsLazily functionality.
A.CallTo(() => repAssign.FindAll(A<DateTime>.Ignored,A<DateTime>.Ignored,A<Guid>.Ignored,A<Gender>.Ignored,A<Int>.Ignored))
.ReturnsLazily((DateTime StartDate, DateTime EndDate, Guid locationId, Gender gender, int age) =>
return list.Where(...some filters here as per arguments...).ToList();
);
With FakeItEasy, please suggest how to use ReturnsLazily for methods which has more than 4 arguments.
You need to use overload that takes
IFakeObjectCall
as lambda parameter and extract arguments from there:Arguments can be extracted via
GetArgument
generic method which takes argument type as generic parameter and argument position (0-based).On a side note, you should consider refactoring of such method. This many parameters are better wrapped into parameter object class:
This will make introduction of new parameters much easier and will help avoid issues like this one.