I'm having a test fail when it calls code that sets a writeonly
property. The property is in an object that I'm mocking with
RhinoMocks.
The method I'm testing is:
        Public Overrides Sub OnViewLoaded()

            AddHandler View.ClearClicked, AddressOf View_ClearClicked
            AddHandler View.SearchClicked, AddressOf
View_SearchClicked

            LoadKeyOnView()
        End Sub


        Private Sub LoadKeyOnView()

            View.Key = Controller.SelectForSearch()
        End Sub

My test is failing in LoadKeyOnView. when it assigns the result of
Controller.SelectForSearch to the View.Key property.

The error I get is
Test method
ClientSearchTesting.ClientSearchPresenterUnitTest.ClientSearchPresenter_OnViewLoadedTest
threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException:
IClientSearchView.set_Key
(ATO.RM.Sample.Document.ClientSearchKeyDocument); Expected #0, Actual
#1..

I'm mocking the View that has this Key property. I believe this means
I have to set an expectation for the View.Key property being accessed
during my test. Normally I'd code
Rhino.Mocks.Expect.Call(mockView.Key).Return(New ClientSearchDocument
())

But this doesn't compile: the property Key is a writeonly property.

What should I do to set the expectation properly?

My test method - it has some custom mock objects at the start. Please
disregard them - the problem is in the Rhino-mocked mockView object.

<TestMethod()> _
    Public Sub ClientSearchPresenter_OnViewLoadedTest()

        mocks = New MockRepository()
        mockState = New PrePostMockState()
        mockNavigator = New NavigatorMock(mockState)

        Dim controller As IClientSearchController
        controller = New ClientSearchController(mockNavigator)

        Dim mockView As IClientSearchView
        mockView = mocks.StrictMock(Of IClientSearchView)()
        AddHandler mockView.ClearClicked, Nothing
        Dim clearClickedRaiser As Rhino.Mocks.Interfaces.IEventRaiser
= LastCall.IgnoreArguments().GetEventRaiser()
        AddHandler mockView.SearchClicked, Nothing
        Dim searchClickedRaiser As Rhino.Mocks.Interfaces.IEventRaiser
= LastCall.IgnoreArguments().GetEventRaiser()

        'Rhino.Mocks.Expect.Call(mockView.Key).Return(New
ClientSearchDocument())

        Dim target As ClientSearchPresenter = New ClientSearchPresenter
(controller) ' TODO: Initialize to an appropriate value
        target.View = mockView
        mockState.Replay()
        mocks.ReplayAll()

        target.OnViewLoaded()

        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