Sub: "Expression doesn't produce a value"

217 views
Skip to first unread message

mpha...@gmail.com

unread,
Aug 26, 2008, 2:41:39 PM8/26/08
to Moq Discussions
I've not mocked at all before and am trying to learn how to get a
simple test working with a Sub in VB (same as void in C#).
If I change the lamba to call Save instead of Insert this error goes
away and everything works fine. Can anyone help me?


Here's the error "Expression does not produce a value.":

Error 1 Overload resolution failed because no accessible 'Expect' can
be called with these arguments:
'Public Function Expect(Of TResult)(expression As
System.Linq.Expressions.Expression(Of System.Func(Of
CSDALC.IManagerBase(Of CSDALC.PolHDAL, CSDALC.PolHDALCollection),
TResult))) As Moq.Language.Flow.IExpect(Of TResult)': Expression does
not produce a value.
'Public Function Expect(Of TResult)(expression As
System.Linq.Expressions.Expression(Of System.Func(Of
CSDALC.IManagerBase(Of CSDALC.PolHDAL, CSDALC.PolHDALCollection),
TResult))) As Moq.Language.Flow.IExpect(Of 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 Expect(expression As
System.Linq.Expressions.Expression(Of System.Action(Of
CSDALC.IManagerBase(Of CSDALC.PolHDAL, CSDALC.PolHDALCollection)))) As
Moq.Language.Flow.IExpect': Expression does not produce a value. C:\...
\Visual Studio 2008\Projects\CS\CSBLUnitTests\PolHTest.vb 72 9
CSBLUnitTests

Option Infer On

Public Interface IManagerBase(Of t, tColl As {SortedBindingList(Of t),
New})
Sub Insert(ByRef inObject As t)
Function Load(ByVal id As Integer) As t
Function Save(ByVal inObject As t) As Integer
Function Delete(ByVal inObject As t) As Integer
End Interface


Dim mockDataAccessManager As New Mock(Of IManagerBase(Of PolhDAL,
polhDALCollection))
Dim target As Polh_Accessor = New Polh_Accessor
Dim polh As New PolhDAL
MockDataAccessManager.Expect(Function(x) x.Insert(polh))

Daniel Cazzulino

unread,
Aug 27, 2008, 3:43:17 PM8/27/08
to moq...@googlegroups.com
you have a compilation error. the compiler cannot determine which overload you want to invoke.

see the error "

Error   1       Overload resolution failed because no accessible 'Expect' can
be called with these arguments:"

and the suggestion to "Specifying the data type(s) explicitly might correct this error."

Michael

unread,
Aug 28, 2008, 2:50:46 PM8/28/08
to Moq Discussions
It's obvious there is a compiler error but it doesn't make sense to me
because the exact same code works in C# without an error.
Here's a simpler example which compiles correctly in C#:

[TestMethod]
public void TestMoqInterface()
{
Mock<ITestMoq> testMoq = new Mock<ITestMoq>();

testMoq.Expect(x => x.DoSomthingAndreturn(3));
testMoq.Expect(x => x.DoSomething(3));
}
}
}
public interface ITestMoq{
void DoSomething(int value);
bool DoSomthingAndreturn(int value);
}

Drop this code into a VB project and you get a compiler error on the
2nd Expect statement:

Option Infer On
<TestMethod()> _
Public Sub TestMoqInterface()
Dim testMoq As New Mock(Of ITestMoq)
testMoq.Expect(Function(x) x.DoSomthingAndReturn(3)) 'this
line compiles without error
testMoq.Expect(Function(x) x.DoSomething(3)) 'this line won't
compile

End Sub

End Class

Public Interface ITestMoq
Sub DoSomething(ByVal Value As Integer)
Function DoSomthingAndReturn(ByVal Value As Integer) As Boolean
End Interface

Please show me any example similar to the QuickStart documentation
"ShouldExpectCallWithoutReturnValue" ...it seems as if there's a bug
or some VB syntax that I'm not getting.

Thanks for your time,
Michael

Michael

unread,
Aug 28, 2008, 3:03:29 PM8/28/08
to Moq Discussions
...also, as to your suggestion, I specified the data type and was met
with the same compiler error as before.

testMoq.Expect(Function(x As ITestMoq) x.DoSomething(3)) 'this
line still won't compile

Michael

unread,
Aug 28, 2008, 3:50:59 PM8/28/08
to Moq Discussions
If you look at Issue 61 in the Issues tab of this project...evidently
Moq doesn't work with Visual Basic... that is unfortunate. It would be
nice if this information was featured more conspicuously as I've
invested a bunch of time only to find this dead end :(

Daniel Cazzulino

unread,
Aug 28, 2008, 4:50:31 PM8/28/08
to moq...@googlegroups.com
just changed the project tagline to:

The simplest mocking library for .NET 3.5 and C# 3.0

so it's now explicit that it's intended for C#

Daniel Cazzulino

unread,
Aug 28, 2008, 4:55:29 PM8/28/08
to moq...@googlegroups.com
actually, I just reverted it.
it's not true we don't want it to work with VB, it's just that I haven't done any VB in years, and really have no idea what it should do/what doesn't work in VB.

we'll need your help :)

Michael

unread,
Aug 29, 2008, 9:26:17 AM8/29/08
to Moq Discussions
I'd love to help. I'll try to test some more to see if I can find
anything else that doesn't work.

Daniel Cazzulino

unread,
Aug 29, 2008, 12:31:21 PM8/29/08
to moq...@googlegroups.com
I don't know about type inferencing tules in VB.NET, but have you tried this same code by specifying all types explictly?

Michael

unread,
Sep 2, 2008, 9:31:09 AM9/2/08
to Moq Discussions
Explicity specifiying types gives the same error, unfortunatly.

Michael
> > anything else that doesn't work.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages