I have a method as following:
public static void Debug(string message, int eventId)
{
if (DoILog(LogLevelKey.LogVerboseMsgToEventLog))
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
Logger.Write(eventId, null, message, null, "General", 0, LogStatus.Success, TraceEventType.Verbose);
});
}
}
I need to mock the SPSecurity.RunWithElevatedPrivileges method which is a static method but it accepts a delegate as the input parameter. Inside the delegate implementation there is another static method: Logger.Write(...).
I wrote this:
SPSecurity.CodeToRunElevated inputArgument = delegate
{
Logger.Write(_eventId, null, _message, null, "General", 0, LogStatus.Success, TraceEventType.Verbose);
};
Action spSecurityAction = delegate { SPSecurity.RunWithElevatedPrivileges(inputArgument); };
Isolate.WhenCalled(spSecurityAction).IgnoreCall();
But it complains that it can't mock that static method because it has a delegate instance as input parameter.
How could I mock SPSecurity.RunWithElevatedPrivileges?
Thanks