Hi Doron,
I've just changed the design of the SystemNodeMenu class, and it's led to another problem.
Previously, SystemNodeMenu had a reference to a SystemNodePresenter instance, and when the Edit menu item was clicked it would call the presenter's Edit() method. I could easily test that by faking a presenter instance and checking that its Edit() method had been called.
But that design doesn't conform to the MVP pattern, where the view has no reference to the presenter. So I've modified the SystemNodeMenu class to raise an Edit event when its Edit menu item is clicked, and then the presenter responds to that event as follows:
public class SystemNodeMenu : ContextMenuStrip
{
public event EventHandler Edit;
public SystemNodeMenu( SystemNodePresenter presenter )
{
ToolStripMenuItem _editItem = new ToolStripMenuItem( "&Edit" );
_editItem.Click += EditItem_Click;
Items.AddRange( new ToolStripMenuItem[] { _editItem } );
}
private void EditItem_Click( object sender, EventArgs e )
{
if ( Edit != null )
Edit( sender, e );
}
}
public class SystemNodePresenter
{
public void ContextMenu( TreeNode treeNode )
{
SystemNodeMenu menu = new SystemNodeMenu();
menu.Edit += Edit;
menu.Show();
}
public void Edit( object sender, EventArgs e )
{
// Do something
}
}
It's easy to test if the SystemNodePresenter subscribes to the Edit event, but is there a simple way to test if SystemNodeMenu actually fires the Edit event when its menu item is clicked?
Denis