Mocking VB.NET Methods With Moq

跟風遠走 提交于 2019-12-04 07:17:36
Steven Lyons

As you've found, the current version of VB.NET (VB9) only allows lambda methods that return a value (ie. Function lambdas). There's not really much you can do about that other than to create a function to return a dummy value. I can't test it at the moment, so I'm not sure that is a viable workaround for this case.

In the next version of VB.NET (VB10), the language will support Sub lambdas and should help in these cases.

It seems other people are also having trouble of differing degrees with the current Moq/VB.NET combination.

Val

In Visual Studio 2010 use

serviceMock.Setup(Sub(c) c.MethodName(paramName))

Also, make sure that the mocked entity (serviceMock) is either mocked as an interface, or has MethodName declared as overrideable.

Arnis Lapsa

It seems that this seals the deal.

Kind a dissapointing - investigation took me quite a lot of time. :/

Typemock has support for VB.NET friendly API for that purpose: http://site.typemock.com/vbpage/2009/9/10/unit-testing-vbnet.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!