Using Microsoft fakes i have the following method signature in my stub object:
public void GetAllOf1ExpressionOfFuncOfT0M0Int32Int32<T2>(FakesDelegates.Func<Expression<System.Func<T, T2>>, int, int, IList<T>> stub);
which is the stub method for this real one:
IList<T> GetAll<T2>(Expression<Func<T, T2>> orderbyexpr, int nStartAt = -1, int NumToSel = -1);
What i would like to do is assigning the stub method with custom stuff by using this method:
public static RunReport StubMethod<T>(ref FakesDelegates.Func<T> func, T returnValue)
{
var counter = new RunReport();
func = () =>
{
Interlocked.Increment(ref counter.Count);
return returnValue;
};
return counter;
}
the problem i have is that i cant understand what the signature of StubMethod shoudld be and how can i call it?
i tried couple of thing which led me to "method group cannot be assigned/cannot cast the method group".
BTW - it working perfectly with other simpler stub method like this:
IList<T> IRepository<T>.GetAll();
so it must be definition issue...
this is where i use GetAll in the code... this should be redirect to my custom function:
public IList<EntityType> GetAllEntityTypesByName(string filter)
{
IList<EntityType> types = new List<EntityType>();
try
{
using (IUnitOfWork uow = ctx.CreateUnitOfWork(true))
{
IRepository<EntityType> repType = uow.CreateRepository<EntityType>();
if (string.IsNullOrEmpty(filter))
{
types = repType.GetAll(o => o.Name);
}
else
{
types = repType.Find(t => t.Name.ToLower().Contains(filter.ToLower()), o => o.Name);
}
}
}
catch (Exception e)
{
ResourceManager.Instance.Logger.LogException(e);
}
return types;
}
Another way to look at the problem is that i want to replace this:
stubRepType.GetAllOf1ExpressionOfFuncOfT0M0Int32Int32<string>((a, b, c) => { return new List<EntityType>(); });
with this:
TestHelper.StubRepositoryMethod<IList<EntityType>>(ref stubRepType.GetAllOf1ExpressionOfFuncOfT0M0Int32Int32<string>, new List<EntityType>());