RhinoMocks AAA extensions for VB.Net ?

40 views
Skip to first unread message

Tarpan

unread,
Dec 10, 2009, 10:39:52 PM12/10/09
to Rhino.Mocks
Hi there,

I like AAA syntax a lot, but using it in VB may be pain in a butt. I'm
thinking to write a few extensions for RhinoMocks to support VB
better, but first just wondering - maybe somebody can recommend a
ready solution?

Few examples:

1) AssertWasCalled for a Sub:
DataSaver.AssertWasCalled(Function(x) x.Save(Data))
looks easy but does not work in VB

extension like this may help
DataSaver.AssertSubWasCalled(Of IDataObject)(AddressOf
DataSaver.Save, Data)

2) Repeat
DataSaver.AssertWasCalled(Function(x) x.SaveFunc(Data), function(o)
o.Repeat.Once)
looks easy but does not work in VB

and probably few others VB issues

Tim Barcz

unread,
Dec 11, 2009, 8:21:43 AM12/11/09
to rhino...@googlegroups.com
What is the error you get?

Sent from my iPhone
> --
>
> You received this message because you are subscribed to the Google
> Groups "Rhino.Mocks" group.
> To post to this group, send email to rhino...@googlegroups.com.
> To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en
> .
>
>

Tarpan

unread,
Dec 11, 2009, 10:23:33 AM12/11/09
to Rhino.Mocks
The error is about limited Lambda expressions in VB - Lambda
expression has to return a value. Exact error text is
--------------
Error 2 Overload resolution failed because no accessible
'AssertWasCalled' can be called with these arguments:
Extension method 'Public Sub AssertWasCalled(action As System.Func
(Of IDataSaver, Object))' defined in
'Rhino.Mocks.RhinoMocksExtensions': Expression does not produce a
value.
Extension method 'Public Sub AssertWasCalled(action As
System.Action(Of IDataSaver))' defined in
'Rhino.Mocks.RhinoMocksExtensions': Expression does not produce a
value. D:\GMS5000\Server\TDD_SmartTruck\CRFTagLocator_specs.vb 132 9
TDD_SmartTruck
--------------
Don't spend time to understand the error message - it just means that
"Lambda expression has to return a value".


On Dec 11, 8:21 am, Tim Barcz <timba...@gmail.com> wrote:
> What is the error you get?
>
> Sent from myiPhone
>

devghost

unread,
Jan 8, 2010, 7:58:28 AM1/8/10
to Rhino.Mocks

Did you figure this out? If not, here is what I do (regarding the
first problem), create
a fake function that can be used in the Lambda expression. It's way
more ugly but it makes it work in VB.

Here's an example, in the FakeErrorMessage i call the method or
property that doesn't have
ant return value...

view.Stub(Function(x As IObjectSelectionView) FakeErrorMessage(x,
validationResult))

Private Function FakeErrorMessage(ByVal e As IObjectSelectionView,
ByVal validationResult As ValidationResult) As Boolean
e.ErrorMessages = ValidationResult.ErrorMessages
Return True
End Function


There's probably an easier way to do this, but haven't found it
yet :o)


Kind Regards
Robert

Reply all
Reply to author
Forward
0 new messages