<TestMethod()> _ Public Sub Can_Update_User() ' Arrange _membershipService.Setup(Function(x) x.UpdateUser(It.IsAny(Of MembershipUser))) Dim controller As New UsersController(_membershipService.Object,_roleProvider.Object,_supportWorksService.Object,_portalClientService.Object) ' Act Dim result As ViewResult = controller.Edit("testUser",New FormCollection) ' Assert Assert.AreEqual("Index",result.ViewName) End Sub
模拟的成员资格服务的设置将无法编译,错误是:
Overload resolution Failed because no
accessible ‘Setup’ can be called with
these arguments:‘Public Function
Setup(Of TResult)(expression As
System.Linq.Expressions.Expression(Of
System.Func(Of
Services.IMembershipService,
TResult))) As
Moq.Language.Flow.ISetup(Of
Services.IMembershipService,
TResult)’: Expression does not produce
a value.‘Public Function Setup(Of
TResult)(expression As
System.Linq.Expressions.Expression(Of
System.Func(Of
Services.IMembershipService,
TResult)’: Data type(s) of the type
parameter(s) cannot be inferred from
these arguments. Specifying the data
type(s) explicitly might correct this
error.‘Public Function
Setup(expression As
System.Linq.Expressions.Expression(Of
System.Action(Of
Services.IMembershipService))) As
Moq.Language.Flow.ISetup(Of
Services.IMembershipService)’:
Expression does not produce a value.
我错过了什么?我是否必须创建一个假类,而不是在我的班级有一个我想要调用它的方法时使用Moq?
编辑:
好吧,一点点阅读表明这是由于使用Function()必须有结果的lambda在VB中表达的方式.
在next version of VB.NET(VB10)中,该语言将支持Sub lambdas,并应在这些情况下提供帮助.
似乎其他人也与目前的Moq / VB.NET组合有不同程度的having trouble.