I managed to get the test that was generating the error to pass.
Here's what the error ended up being: I had a property on a mocked
object that was a List. When I set an expectation for a property
accessor for that List, I created an object as follows.

        ' when the presenter calls its LoadKeyOnView method, it will
assign to the View.Summary property by accessing the
Controller.Summary property.
        ' Create some dummy documents for these accessors.
        Dim expectedViewSummary As New List(Of
ClientSearchSummaryDocument.ClientSearchSummaryFieldsDocument)
        ' add one value to this list
        expectedViewSummary.Add(New
ATO.RM.Sample.Document.ClientSearchSummaryDocument.ClientSearchSummaryFieldsDocument
())

        ' set up expectation that view.Summary will be written to
        mockView.Summary = expectedViewSummary

Turns out that I wasn't allowed to add any values into the list in
setting the expectation. That is, the test passes if I change the code
to this.
        Dim expectedViewSummary As New List(Of
ClientSearchSummaryDocument.ClientSearchSummaryFieldsDocument)

        mockView.Summary = expectedViewSummary

I'm still not sure why the property expectation had to be met by an
empty List rather than one with one item in it.

I must say also that the error message for this was very unhelpful.
Test method
ClientSearchTesting.ClientSearchResultsPresenterUnitTest.ClientSearchResultsPresenter_OnViewLoadedTest
threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException:
IClientSearchResultsView.set_Summary(System.Collections.Generic.List`1
[ATO.RM.Sample.Document.ClientSearchSummaryDocument
+ClientSearchSummaryFieldsDocument]); Expected #1, Actual #0..

How was this supposed to let me know that the extra item was causing
problems? I only found this when I rewrote the test using NMock2 today
and was working through the error messages it generated.

Anyway, thanks to both Ayende and Kenneth who took the time to read
this and try to help. For any interested, the final code for the test
is:
    <TestMethod()> _
    Public Sub ClientSearchResultsPresenter_OnViewLoadedTest()
        ' OnViewLoaded in the presenter does the following:
        ' - adds event handlers for the View's SelectedIndexChanged
and SelectedPageChanged events
        ' - calls the private function LoadSummaryOnView, which calls
a Controller method and assigns the result to the View.Summary
property in the presenter
        ' -  sets the View.SelectedPage property to the
Controller.SelectedPage property.

        ' Mock a controller and a View for use by the presenter in
this test
        Dim mockController As IClientSearchController
        mockController = mocks.DynamicMock(Of IClientSearchController)
()
        Dim mockView As IClientSearchResultsView
        mockView = mocks.DynamicMock(Of IClientSearchResultsView)()

        ' set up expectation that during the test, the Presenter being
tested will add a
        ' handler to the View's events and that this event handler
will not be null
        AddHandler mockView.SelectedIndexChanged, Nothing
        LastCall.Constraints(Rhino.Mocks.Constraints.Is.NotNull())
        AddHandler mockView.SelectedPageChanged, Nothing
        LastCall.Constraints(Rhino.Mocks.Constraints.Is.NotNull())

        ' when the presenter calls its LoadKeyOnView method, it will
assign to the View.Summary property by accessing the
Controller.Summary property.
        ' Create some dummy documents for these accessors.
        Dim expectedViewSummary As New List(Of
ClientSearchSummaryDocument.ClientSearchSummaryFieldsDocument)
        '' Note: adding this line of code will cause the test to fail.
Not sure why - the expectation for the mockView.Summary has to be an
empty document.
        '' add one value to this list
        'expectedViewSummary.Add(New
ATO.RM.Sample.Document.ClientSearchSummaryDocument.ClientSearchSummaryFieldsDocument
())

        ' set up expectation that view.Summary will be written to
        mockView.Summary = expectedViewSummary

        Dim expectedControllerSummary As New
ClientSearchSummaryDocument()
 
'expectedControllerSummary.ClientSearchSummaryFieldsCollection. _
        '' Note: adding this line of code will cause the test to fail.
Not sure why - the expectation for the mockView.Summary has to be an
empty document.
        ''Add(New
ATO.RM.Sample.Document.ClientSearchSummaryDocument.ClientSearchSummaryFieldsDocument
())

        ' set expectation that controller's SummaryDocument will be
accessed
        Rhino.Mocks.Expect.Call(mockController.SummaryDocument).Return
(expectedControllerSummary)

        ' set expectation that View.SelectedPage will be assigned to
        mockView.SelectedPage = 0
        'Rhino.Mocks.Expect.Call(mockView.SelectedPage).Return(0)
        ' set expectation that Controller.SelectedPage will be called
        Rhino.Mocks.Expect.Call(mockController.SelectedPage).Return(0)

        mocks.ReplayAll()

        Dim target As ClientSearchResultsPresenter = New
ClientSearchResultsPresenter(mockController)
        target.View = mockView

        target.OnViewLoaded()

        Assert.IsTrue(target.View.SelectedPage =
target.Controller.SelectedPage)

        ' verify that all expectations set up for this test have been
met on all mock objects
        mocks.VerifyAll()

    End Sub



--~--~---------~--~----~------------~-------~--~----~
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