Click or drag to resize

RaiseAssertionsRaisedT Method (SmartAssertPlaceHolder, String, EventHandlerT)

Creates an Assertion that ensure an standard event is raised in the Act part of your test.

Namespace:  SmartTests.Assertions
Assembly:  SmartTests (in SmartTests.dll) Version: 1.10.0
public static Assertion Raised<T>(
	this SmartAssertPlaceHolder this,
	string expectedEventName,
	EventHandler<T> assert
where T : EventArgs


Type: SmartTestsSmartAssertPlaceHolder
The dummy place holder for all Smart Assertions.
Type: SystemString
The name of the event that should raise.
Type: SystemEventHandlerT
The handler that must be run in Act part to do specific assertions.

Type Parameters

The type of the EventHandlerTEventArgs of the event that should raise.

Return Value

Type: Assertion
The newly created Assertion.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type SmartAssertPlaceHolder. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
ArgumentNullException If expectedEventName is null.
ArgumentException If expectedEventName is empty.
BadTestException If the expectedEventName is not a valid event of the type of the instance involved in the Act.
SmartTestException If the expectedEventName event is not raised.
This Assertion ensures that:
  1. Before the Act -

    The expectedEventName exists in the type of the instance involved in the Act type; otherwise a BadTestException is thrown.

  2. During the Act -

    Invoke the assert handler, to test specific assertions.

  3. After the Act -

    If the event was not raised, a SmartTestException is thrown.


In this example, the Smart Assertion verifies that the MyEvent event is raised for mc.

It also ensure anything you want in the specified handler.

public void MyMethodTest()
    var mc = new MyClass();
    RunTest( ValidValue.IsValid,
             () => mc.MyMethod(),
             SmartAssert.Raised( "MyEvent",
                                 ( sender, args ) => {
                                                         // Check anything you want when MyEvent is raised.
See Also