我在c#中有一个表达式og MOQ(lambda / linq)。当试图在vb.net中使用此代码时,我收到错误
C#代码
_dataLayerMock.Setup(x => x.SaveAccount(It.Is<Account>(a => a.AccountType == AccountType.Private)));
转换后的VB.net代码
_dataLayerMock.Setup(Function(x) x.SaveAccount(It.[Is](Of Account)(Function(a) a.AccountType = AccountType.[Private])))
错误
Error 1 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 ConsoleApplication1.IDataLayer, TResult))) As Moq.Language.Flow.ISetup(Of ConsoleApplication1.IDataLayer, TResult)': Expression does not produce a value.
'Public Function Setup(Of TResult)(expression As System.Linq.Expressions.Expression(Of System.Func(Of ConsoleApplication1.IDataLayer, TResult))) As Moq.Language.Flow.ISetup(Of ConsoleApplication1.IDataLayer, 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 ConsoleApplication1.IDataLayer))) As Moq.Language.Flow.ISetup(Of ConsoleApplication1.IDataLayer)': Expression does not produce a value. D:\Araamudhan\Project\Amex\Maven-NPanday\Application\ClassLibrary\LinqTest\LinqTest\BusinessLayerTest.vb 20 9 LinqTest
任何人都可以帮我解决这个问题吗
答案 0 :(得分:2)
使用其中一个代码转换器 - 它们派上用场非常适合这些实例。 http://converter.telerik.com/
_dataLayerMock.Setup(Function(x) x.SaveAccount(It.[Is](Function(a) a.AccountType = AccountType.[Private])))
HTH
答案 1 :(得分:0)
你可能不再需要这个答案,但万一其他人遇到这个问题。
我相信这在VB.net中不起作用,因为lambdas必须在vb中返回一个值,所以不允许你在VB中模拟一个sub方法。
希望这有帮助