MockExpectAddEventAlways Method

Typemock Isolator Developer Guide
Expect unlimited number of event listeners to be added (event += new EventHandler())

Namespace:  TypeMock
Assembly:  TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
Syntax

public MockedEvent ExpectAddEventAlways(
	string eventName
)

Parameters

eventName
Type: SystemString
Name of Event

Return Value

Type: MockedEvent
A MockedEvent that can be used to Fire(Object) the Event

Implements

IMockControlExpectAddEventAlways(String)
Remarks

When more than one instance of the event published is mocked, use the MockedEvent.Instance[index] property The first instance to register to the event will be in index 0, the next instance in 1 and so on.
[Test]
public void SimulateFiringClickOnManyButtons()
{
  // Mock all Click Events of the all Buttons
  Mock buttonMock = MockManager.MockAll(typeof(Button)); 
  MockedEvent handle = buttonMock.ExpectAddEventAlways("Click");

  // create 2 buttons and register to the Click Event
  Button button1 = new Button();
  Button button2 = new Button();
  button1.Click += new EventHandler(button_Click);
  button2.Click += new EventHandler(button_Click);

  // Simulate firing Click of button1
  handle.Instance[0].Fire(this, EventArgs.Empty);
  // Simulate firing Click of button2
  handle.Instance[1].Fire(this, EventArgs.Empty);
  // Check that system works...

  MockManager.Verify()
}
Since Version 3.7
See Also

Reference