Raises Method (MockedEvent, )

Moq 2.6

Specifies the mocked event that will be raised when the expectation is met.

Namespace:  Moq.Language
Assembly:  Moq (in Moq.dll) Version: 2.6.1014.1 (2.6.0.0)

Syntax

C#
IVerifies Raises(
	MockedEvent eventHandler,
	EventArgs args
)

Parameters

eventHandler
Type: Moq..::.MockedEvent
The mocked event, retrieved from CreateEventHandler()()() or CreateEventHandler<(Of <(TEventArgs>)>)()()().
args
Type: EventArgs
The event args to pass when raising the event.

Examples

The following example shows how to set an expectation that will raise an event when it's met:
CopyC#
var mock = new Mock<IContainer>();
// create handler to associate with the event to raise
var handler = mock.CreateEventHandler();
// associate the handler with the event to raise
mock.Object.Added += handler;
// set the expectation and the handler to raise
mock.Expect(add => add.Add(It.IsAny<string>(), It.IsAny<object>()))
    .Raises(handler, EventArgs.Empty);

See Also