It feels like I'm almost got it working now.. just one small thing,
this is what I got:
<Test()> _
Public Sub It_should_return_a_validationresult_errormessage_aaa()
' Arrange
domain.Stub(Function(e As ObjectSelectionDomain) e.GetObjects
(Nothing, Nothing)).IgnoreArguments().Return(New List(Of
ObjectDto)).OutRef(ValidationResult)
view.Expect(Function(x As IObjectSelectionView)
FakeErrorMessage(x, validationResult))
' Act
Dim presenter As ObjectSelectionPresenter = New
ObjectSelectionPresenter(view, domain)
presenter.GetObjects()
' Assert
view.VerifyAllExpectations()
End Sub
Private Function FakeErrorMessage(ByVal e As IObjectSelectionView,
ByVal validationResult As ValidationResult) As Boolean
e.ErrorMessages = ValidationResult.ErrorMessages
Return True
End Function
The above test works, the outref contains my error message. Since VB9
doesn't support anonymous
delegates I needed to use a fake method to put my expectations on.
However, if I am going to use
the way you proposed in replacing the Expect call with view.Stub, the
test looks like this:
<Test()> _
Public Sub It_should_return_a_validationresult_errormessage_aaa()
' Arrange
domain.Stub(Function(e As ObjectSelectionDomain) e.GetObjects
(Nothing, Nothing)).IgnoreArguments().Return(New List(Of
ObjectDto)).OutRef(ValidationResult)
view.Stub(Function(x As IObjectSelectionView) FakeErrorMessage
(x, validationResult))
' Act
Dim presenter As ObjectSelectionPresenter = New
ObjectSelectionPresenter(view, domain)
presenter.GetObjects()
' Assert
view.AssertWasCalled(Function(x As IObjectSelectionView)
FakeErrorMessage(x, validationResult))
End Sub
This test fails giving the error message
"IObjectSelectionView.set_ErrorMessages
(System.Collections.Generic.List`1[System.String]); Expected #1,
Actual #2.", meaning
my view.ErrorMessages writeonly property is called twice instead of
one time. Am i doing something wrong with Rhino Mocks, or might it be
my
usage of the fake method?
Thanks!
On 16 Nov, 16:08, Alex McMahon <
fluxmu...@gmail.com> wrote:
> Indeed, I think you get much better responses here if you post in C#, I find
> it a real head trip translating VB...
>
> A small point, but 'Arrange' would cover your stubbing as well. The only bit
> that would be counted as 'Act' is presenter.GetObjects(). You would then
> put any assertions in a 'Assert' section.
>
> You need to get rid of:
> view.Expect(Function(e As IObjectSelectionView) e.ErrorMessages =
> validationResult.ErrorMessages
> view.VerifyAllExpectations()
>
> instead you should have view.Stub(x=>x....
> and view.AssertWasCalled(x=>x....
>
> It might feel like you're having to write a stub and an assert whereas
> before you just had an Expect, but it makes a lot more sense eventually. You
> should see it that Stub() is to support your test getting to the code you
> want to exercise (and not throwing). and that AssertWasCalled is your actual
> test.
>
> 2009/11/16 devghost <
robertbl...@gmail.com>