Sorry, but I can't seem to get my head around the VBness of it all... I did read about having to use those fake methods, but not sure whether it could be the cause (although I doubt it). The first place I would look is whether the presenter is indeed setting the ErrorMessages twice.
2009/11/17 devghost <[email protected]> > > > 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 <[email protected]> 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 <[email protected]> > > > > > > > > > > > > > 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 -~----------~----~----~----~------~----~------~--~---
