tags:

views:

54

answers:

1

I have a problem with VB9 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), Times.AtLeastOnce)

I have tried this, but i get:

Lambda Parameter not in scope

+1  A: 

VB10 allows for the usage of Lambada Subs.

Have you tried a simple wrapper, such as:

Public Function Wrapper(source as Action) as Boolean  
    source.Invoke()   
    Return True 
End Function
M.A. Hanin