Thanks for the reply, Kenneth. But no luck.
I've just tried moving the test's code around so that ReplayAll is
called before any mocked object is used. It still doesn't run: This
test will fall over with an exception on the line where I set an
expectation for a controller.SelectedPage property. I'm fairly sure
this isn't related to the test being written in VB as the code is very
similar to another test I have that runs successfully. The difference
is that in the test that runs successfully, I'm setting an expectation
for a method call rather than a property accessor.
'''<summary>
'''A test for OnViewLoaded
'''</summary>
<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)
()
' set expectation that Controller.SelectedPage will be called
- TEST THROWS EXCEPTION AT RUNTIME HERE
' System.InvalidOperationException: Previous method
'IClientSearchController.get_SelectedPage();' requires a return value
or an exception to throw..
Rhino.Mocks.Expect.Call(mockController.SelectedPage).Return(0)
' when the presenter calls its LoadKeyOnView method, it will
assign to the View.Summary property. Set up expectation for this write-
only property
Dim fakeSummary As New ClientSearchSummaryDocument()
fakeSummary.ClientSearchSummaryFieldsCollection.Add(New
ClientSearchSummaryDocument.ClientSearchSummaryFieldsDocument())
' The onViewLoaded method will access a method on the
presenter's View property,
' so we need to mock one up.
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())
' set up expectation that view.Summary will be written to
mockView.Summary =
fakeSummary.ClientSearchSummaryFieldsCollection
' set expectation that View.SelectedPage will be called
Rhino.Mocks.Expect.Call(mockView.SelectedPage).Return(0)
' set expectation that controller's property will be called
Rhino.Mocks.Expect.Call(mockController.SummaryDocument).Return
(fakeSummary)
mocks.ReplayAll()
Dim target As ClientSearchResultsPresenter = New
ClientSearchResultsPresenter(mockController)
target.View = mockView
target.OnViewLoaded()
' verify that all expectations set up for this test have been
met on all mock objects
mocks.VerifyAll()
Assert.IsTrue(target.View.SelectedPage =
target.Controller.SelectedPage)
End Sub
ERROR STACK TRACE
Rhino.Mocks.Impl.RecordMockState.AssertPreviousMethodIsClose()
Rhino.Mocks.Impl.RecordMockState.MethodCall(IInvocation invocation,
MethodInfo method, Object[] args)
Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object
proxy, MethodInfo method, Object[] args)
Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation)
Castle.DynamicProxy.AbstractInvocation.Proceed()
IClientSearchControllerProxycbaed3758be247d5b5d9bd8c68424dc0.get_SelectedPage
()
ClientSearchTesting.ClientSearchResultsPresenterUnitTest.ClientSearchResultsPresenter_OnViewLoadedTest
() in D:\WORKAREA\
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---