Moq a Sub

While mocking a VB method I was getting the following error :

‘Public Function Setup(expression As System.Linq.Expressions.Expression(Of System.Action(Of EmailSender.IMailManager))) As Moq.Language.Flow.ISetup(Of EmailSender.IMailManager)’: Expression does not produce a value

Here’s the moq setup :

mailManager.Setup(Function(x) x.SendEmail(It.IsAny(Of MailManagerSettings))).Verifiable()

Because the SendEmail method is a Sub instead of a Function.

Let’s replace the Setup target Function with a Sub and this will complile. (Sub lambda support is quite new though.)

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *