Situation
There is a generic method that uses TResult which you want to mock using Microsoft Moles.
Problem
You can’t just assign a delegate like on a non-generic method.
Solution
- Create a delegate that behaves like the mocked method should. Define the concrete expected parameter types.
- Instantiate a new MolesDelegates.Func with the corresponding type-parameters and pass the delegate from step 1 as parameter.
- Call the mock and pass the MolesDelegates.Func from step 2 as parameter.
Example
Method to mock:
public static bool Save(TResult pData, string pFile, bool pOverwriteExistingFile)
Assign the mock:
MPersistence.SaveTResultStringBoolean( new MolesDelegates.Func( delegate(PlcData a, string s, bool b) { return false; } ) );
Leave a Reply