Click or drag to resize

PropertyChangedAssertionsRaised_PropertyChangedT Method (SmartAssertPlaceHolder, ExpressionFuncT, T)

Creates an Assertion that ensure an object property/indexer changed to a different value in the Act part of your test.

Namespace:  SmartTests.Assertions
Assembly:  SmartTests (in SmartTests.dll) Version: 1.9.0
public static Assertion Raised_PropertyChanged<T>(
	this SmartAssertPlaceHolder this,
	Expression<Func<T>> expression,
	T expectedValue


Type: SmartTestsSmartAssertPlaceHolder
The dummy place holder for all Smart Assertions.
Type: System.Linq.ExpressionsExpressionFuncT
The expression that will change, directly or indirectly, the property/indexer.
Type: T
The expected value of the property/indexer once the Act part is done.

Type Parameters

The type of the property/indexer that should change.

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).

If expression is not a MemberExpression with a property.

If the involved instance of expression is not an INotifyPropertyChanged instance.

If the member is not a Property.

If the value of the expression is expectedValue before the Act.


If the INotifyPropertyChanged event is not raised.

If PropertyName is not the name of the property/indexer in the Act.

If the current value of the property is not expectedValue in the event handler and after the Act.

This Assertion ensures that:
  1. Before the Act -

    The value of the property/indexer IS NOT expectedValue; otherwise a BadTestException is thrown.

  2. During the Act -

    Ensures the PropertyChanged event is raised.

    The PropertyName is the one in the Act; otherwise a SmartTestException is thrown.

    The value of the property/indexer in the PropertyChanged handler is expectedValue; otherwise a SmartTestException is thrown

  3. After the Act -

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

    The value of the property/indexer is expectedValue; otherwise a SmartTestException is thrown.


In this example, the Smart Assertion verifies that the PropertyChanged event is raised for the property MyProperty and the value is 10.

It also ensures that the value is still 10 after the Act.

public void MyMethodTest()
    var mc = new MyClass();
    RunTest( ValidValue.IsValid,
             () => mc.MyMethod(),
             SmartAssert.Raised_PropertyChanged( () => mc.MyProperty, 10 ) );
See Also