Click or drag to resize

PropertyChangedAssertionsRaised_PropertyChangedT Method (SmartAssertPlaceHolder, T, String, Object)

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.12.0
Syntax
public static Assertion Raised_PropertyChanged<T>(
	this SmartAssertPlaceHolder _,
	T instance,
	string propertyName,
	Object expectedValue
)
where T : INotifyPropertyChanged

Parameters

_
Type: SmartTestsSmartAssertPlaceHolder
The dummy place holder for all Smart Assertions.
instance
Type: T
The instance for which the property/indexer should change.
propertyName
Type: SystemString
The name of the property/indexer that should change.
expectedValue
Type: SystemObject
The expected value of the property/indexer once the Act part is done.

Type Parameters

T
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).
Exceptions
ExceptionCondition
ArgumentNullException If instance or propertyName are null.
BadTestException

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

SmartTestException

If the INotifyPropertyChanged event is not raised.

If PropertyName is not propertyName in the event handler

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

Remarks
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 propertyName; 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.

Examples

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.

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