Wrap Sub as Function for use in Lambda
- by Luhmann
I have a problem with VB and Moq.
I need to call a verify on a Sub. Like so:
logger.Verify(Function(x) x.Log, Times.AtLeastOnce)
And my logger looks like this:
Public Interface ILogger
Sub Log()
End Interface
But with VB this is not possible, because the Log method is a Sub, and thereby does not produce a value.
I don't want to change the method to be a function.
Whats the cleanest way of working around this limitation and is there any way to wrap the Sub as a Function like the below?
logger.Verify(Function(x) ToFunc(AddressOf x.Log))
I have tried this, but i get:
Lambda Parameter not in scope