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.)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s