Click or drag to resize

ChangedToAssertionsChangedToT Method (SmartAssertPlaceHolder, ExpressionFuncT, T)

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

Namespace:  SmartTests.Assertions
Assembly:  SmartTests (in SmartTests.dll) Version: 1.9.0
Syntax
public static Assertion ChangedTo<T>(
	this SmartAssertPlaceHolder this,
	Expression<Func<T>> after,
	T value
)

Parameters

this
Type: SmartTestsSmartAssertPlaceHolder
The dummy place holder for all Smart Assertions.
after
Type: System.Linq.ExpressionsExpressionFuncT
The expression involving a property/indexer whose value should change in the Act part of your test.
value
Type: T
The value to assign to the property/indexer.

Type Parameters

T
The Type of the property/indexer.

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
BadTestExceptionif the property/indexer value BEFORE the Act is value.
SmartTestExceptionif the property/indexer value AFTER the Act is not value.
Remarks
This Assertion ensures that:
  1. Before the Act -

    Evaluates the after expression and raises a BadTestException if it is value.

  2. After the Act -

    Evaluates the after expression and raises a SmartTestException if it is not value.

If you want to test changes of property/indexer and value involved in the Act, prefer using ChangedTo(SmartAssertPlaceHolder)
Examples
In this example, the Smart Assertion verifies that !Equals(mc.MyProperty,10) before the Act part of your test (otherwise a BadTestException is raised) and that Equals(mc.MyProperty,10) after the Act (otherwise a SmartTestException is raised).
[Test]
public void MyMethodTest()
{
    var mc = new MyClass();

    RunTest(AnyValue.Valid,
            () => mc.MyMethod(),
            SmartAssert.ChangedTo(() => mc.MyProperty, 10));
}
See Also