I am taking a look at the AAA syntax and bumped into some issues
converting
the above test. This is what I have done:

Used shared GenerateMock, GenerateStub..
        view = MockRepository.GenerateMock(Of IObjectSelectionView)()
        domain = MockRepository.GenerateStub(Of ObjectSelectionDomain)
()

Modified the test to look like this, I think I got most of it to work
but I'm struggling
with the view...

    <Test()> _
    Public Sub It_should_return_a_validationresult_errormessage_aaa()
        ' Arrange
        Dim validationResult = New ValidationResult("Search String Too
Short!")

        ' Act
        domain.Stub(Function(e As ObjectSelectionDomain) e.GetObjects
(Nothing, Nothing)).IgnoreArguments().Return(New List(Of
ObjectDto)).OutRef(validationResult)

        view.Expect(Function(e As IObjectSelectionView)
e.ErrorMessages = validationResult.ErrorMessages)

        Dim presenter As ObjectSelectionPresenter = New
ObjectSelectionPresenter(view, domain)
        presenter.GetObjects()

        view.VerifyAllExpectations()
    End Sub


The compiler doesn't like the way I call view.Expect with the write-
only ErrorMessages property. Is
there some other way to set a call expectation on write-only
properties? Can't seem to get it working.
Right now I really miss developing in C# :o)


Thanks!



On 16 Nov, 15:07, Tim Barcz <[email protected]> wrote:
> One suggestion that would have helped...unless you must (and you shouldn't)
> use the AAA syntax over the RecordReplay.  It's much clearer and would've
> solved the "Playback" problem right out of the box.
>
> Tim
>
>
>
>
>
> On Mon, Nov 16, 2009 at 8:05 AM, devghost <[email protected]> wrote:
>
> > Indeed, that was it. Now it works as it should. Many thanks to
> > you both you saved my day (been spending a couple of hours to
> > get this to work with no luck).
>
> > Thanks!
>
> > On 16 Nov, 14:59, Alex McMahon <[email protected]> wrote:
> > > I'm probably missing something, but don't you need:
> > > LastCall.*IgnoreArguments()*.Return(New List(Of ObjectDto)).OutRef
> > > (validationResult)
>
> > > is the call to domain.GetObjects in your presenter returning null? or the
> > > empty list you're specifying?
>
> > > 2009/11/16 devghost <[email protected]>
>
> > > > Thanks Tim for your reply, I have corrected the test method to use the
> > > > Playback method.
>
> > > > <Test()> _
> > > > Public Sub It_should_return_a_validationresult_errormessage()
> > > >         Using mocks.Record()
> > > >             Dim validationResult = New ValidationResult("Search String
> > > > Too Short!")
>
> > > >             domain.GetObjects(Nothing, Nothing)
> > > >            LastCall.Return(New List(Of ObjectDto)).OutRef
> > > > (validationResult)
>
> > > >            view.ErrorMessages = validationResult.ErrorMessages
> > > >             LastCall.IgnoreArguments()
> > > >        End Using
>
> > > >        Using mocks.Playback()
> > > >             Dim presenter As ObjectSelectionPresenter = New
> > > > ObjectSelectionPresenter(view, domain)
> > > >            presenter.GetObjects()
> > > >         End Using
> > > > End Sub
>
> > > > However, the problem still remains. When the presenter.GetObjects() in
> > > > turn call the domain.GetObjects(searchString, ByRef validationResult)
> > > > the ByRef (out) validationResult parameter does not contain the error
> > > > message that I wanted it to specified in the Record part.
>
> > > > Kind Regards,
> > > > Robert
>
> > > > On 16 Nov, 13:27, Tim Barcz <[email protected]> wrote:
> > > > > Using (mocks.Playback) will get you into replay mode
>
> > > > > On 11/16/09, Tim Barcz <[email protected]> wrote:
>
> > > > > > Haven't compile checked it it appears from first glance that you
> > never
> > > > > > get into replay mode.  You need to get into replay mode (since
> > you're
> > > > > > doing record/replay) for your return values to work.
>
> > > > > > Hope that helps. Let me know.
>
> > > > > > Tim
>
> > > > > > On 11/16/09, devghost <[email protected]> wrote:
>
> > > > > >> Hi,
>
> > > > > >> I'm fairly new to mocking with Rhino Mocks so bare with me :o)
>
> > > > > >> I got a test where I have stubbed my domain and want a method's
> > > > > >> ByRef parameter to return a specific value, but no matter what I
> > try
> > > > > >> it never returns anything. This is what the test looks like.
>
> > > > > >> <TestFixture()> _
> > > > > >> Public Class
> > When_typing_a_search_string_shorter_than_two_characters2
> > > > > >>     Inherits ContextSpecification
>
> > > > > >>     Private mocks As MockRepository
> > > > > >>     Private view As IObjectSelectionView
> > > > > >>     Private domain As ObjectSelectionDomain
>
> > > > > >>     Private searchString As String
>
> > > > > >>     Protected Overrides Sub Context()
> > > > > >>         mocks = New MockRepository()
>
> > > > > >>         view = mocks.DynamicMock(Of IObjectSelectionView)()
> > > > > >>         domain = mocks.Stub(Of ObjectSelectionDomain)()
> > > > > >>     End Sub
>
> > > > > >>     Protected Overrides Sub Because()
> > > > > >>         searchString = "S"
> > > > > >>     End Sub
>
> > > > > >>     <Test()> _
> > > > > >>     Public Sub It_should_return_a_validationresult_errormessage()
> > > > > >>         Dim validationResult = New ValidationResult("Search String
> > Too
> > > > > >> Short!")
>
> > > > > >>         Using mocks.Record()
> > > > > >>             domain.GetObjects(Nothing, Nothing)
> > > > > >>             LastCall.Return(New List(Of ObjectDto)).OutRef
> > > > > >> (validationResult)
>
> > > > > >>             view.ErrorMessages = validationResult.ErrorMessages
> > > > > >>         End Using
>
> > > > > >>         Dim presenter As ObjectSelectionPresenter = New
> > > > > >> ObjectSelectionPresenter(view, domain)
> > > > > >>         presenter.GetObjects()
>
> > > > > >>         mocks.VerifyAll()
> > > > > >>     End Sub
> > > > > >> End Class
>
> > > > > >> In the call to "domain.GetObjects(?,?)" I want the OutRef to be
> > the
> > > > > >> validationResult
> > > > > >> containing the given error message "Search String Too Short". But
> > It
> > > > > >> always returns
> > > > > >> a ValidationResult without an error message.
>
> > > > > >> Am I doing something obviously wrong here?
>
> > > > > >> Thanks!
>
> > > > > > --
> > > > > > Sent from my mobile device
>
> > > > > > Tim Barcz
> > > > > > Microsoft C# MVP
> > > > > > Microsoft ASPInsider
> > > > > >http://timbarcz.devlicio.us
> > > > > >http://www.twitter.com/timbarcz
>
> > > > > --
> > > > > Sent from my mobile device
>
> > > > > Tim Barcz
> > > > > Microsoft C# MVP
> > > > > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://
> > > >www.twitter.com/timbarcz
>
> --
> Tim Barcz
> Microsoft C# MVP
> Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to