| RaiseAssertionsRaisedT Method (SmartAssertPlaceHolder, Object, 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.12.0
Syntax public static Assertion Raised<T>(
this SmartAssertPlaceHolder _,
Object instance,
string expectedEventName,
EventHandler<T> assert
)
where T : EventArgs
<ExtensionAttribute>
Public Shared Function Raised(Of T As EventArgs) (
_ As SmartAssertPlaceHolder,
instance As Object,
expectedEventName As String,
assert As EventHandler(Of T)
) As Assertion
public:
[ExtensionAttribute]
generic<typename T>
where T : EventArgs
static Assertion^ Raised(
SmartAssertPlaceHolder^ _,
Object^ instance,
String^ expectedEventName,
EventHandler<T>^ assert
)
[<ExtensionAttribute>]
static member Raised :
_ : SmartAssertPlaceHolder *
instance : Object *
expectedEventName : string *
assert : EventHandler<'T> -> Assertion when 'T : EventArgs
Parameters
- _
- Type: SmartTestsSmartAssertPlaceHolder
The dummy place holder for all Smart Assertions. - instance
- Type: SystemObject
The instance for which the event should raise. - expectedEventName
- Type: SystemString
The name of the event that should raise. - assert
- Type: SystemEventHandlerT
The handler that must be run in Act part to do specific assertions.
Type Parameters
- T
- The type of the EventHandlerTEventArgs of the event that should raise.
Return Value
Type:
AssertionThe 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).
Exceptions Remarks
This
Assertion ensures that:
- Before the Act -
The expectedEventName exists in the type of instance type;
otherwise a
BadTestException is thrown.
- During the Act -
Invoke the assert handler, to test specific assertions.
- After the Act -
If the event was not raised, a SmartTestException is thrown.
Examples
In this example, the Smart Assertion verifies that the MyEvent event is raised for mc.InnerObject
inner instance.
It also ensure anything you want in the specified handler.
[Test]
public void MyMethodTest()
{
var mc = new MyClass();
RunTest( ValidValue.IsValid,
() => mc.MyMethod(),
SmartAssert.Raised( mc.InnerObject,
"MyEvent",
( sender, args ) => {
}));
}
See Also