The suggestion to use a MultiMock object was a good one. I didn't know
they existed!

I did some refactoring of the code being tested and rewrote of the
test. THis passes - apologies if there's a typo in it, it's not the
actual code.

1. Introduced an IControllerBase interface instead of having just an
abstract ControllerBase class
    public interface ControllerBase
    {
        /// <summary>
        /// Event raised when a task is being started.
        /// </summary>
        event EventHandler StartTask;
    }

2. Rewrote the code in the class using the controller object to use it
as an IControllerBase instance rather than a ControllerBase instance

  public class MyPresenter
    {

        //...

        public void OnLoad()
        {
            controller.ChangingTabs += this.HandleChangingTabs;
            ((IControllerBase)controller).StartTask +=
this.HandleStartTask;
        }
}

3. Rewrote the test:

[TestMethod()]
public void OnViewLoaded_Test()
{
         // Arrange
        MyPresenter testPresenter = new MyPresenter();
        ControllerBase mockController =
mocks.DynamicMultiMock<IMyController>(typeof(IControllerBase));

          // set up expectation that during the test, the class being
tested will add
         // a handler to the Controller's events and that this event
handler will not be null
        mockController.TaskSuspending += null;
        LastCall.Constraints(Rhino.Mocks.Constraints.Is.NotNull());

        mocks.ReplayAll();

        // Act
        testPresenter.OnViewLoaded();

        // Assert
        mocks.VerifyAll();

}

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