| NotChangedAssertionsNotChangedExceptT Method (SmartAssertPlaceHolder, ExpressionFuncT, NotChangedKind) |
Creates an
Assertion that ensure object properties/fields of the specified instance did not change,
except the specified ones,
in the Act part of your test.
Namespace:
SmartTests.Assertions
Assembly:
SmartTests (in SmartTests.dll) Version: 1.12.0
Syntax public static Assertion NotChangedExcept<T>(
this SmartAssertPlaceHolder _,
Expression<Func<T>> expression,
NotChangedKind kind = NotChangedKind.PublicProperties
)
<ExtensionAttribute>
Public Shared Function NotChangedExcept(Of T) (
_ As SmartAssertPlaceHolder,
expression As Expression(Of Func(Of T)),
Optional kind As NotChangedKind = NotChangedKind.PublicProperties
) As Assertion
public:
[ExtensionAttribute]
generic<typename T>
static Assertion^ NotChangedExcept(
SmartAssertPlaceHolder^ _,
Expression<Func<T>^>^ expression,
NotChangedKind kind = NotChangedKind::PublicProperties
)
[<ExtensionAttribute>]
static member NotChangedExcept :
_ : SmartAssertPlaceHolder *
expression : Expression<Func<'T>> *
?kind : NotChangedKind
(* Defaults:
let _kind = defaultArg kind NotChangedKind.PublicProperties
*)
-> Assertion
Parameters
- _
- Type: SmartTestsSmartAssertPlaceHolder
The dummy place holder for all Smart Assertions. - expression
- Type: System.Linq.ExpressionsExpressionFuncT
The expression of an instance and a property/field. - kind (Optional)
- Type: SmartTests.AssertionsNotChangedKind
The kind of members and visibility to check for changes. Default value is
PublicProperties.
Type Parameters
- T
- The Type of the expression that can change.
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 Exception | Condition |
---|
SmartTestException |
If any property/field checked (see kind) of the instance in expression,
except the
property/field in expression has changed.
|
Remarks
This
Assertion ensures that:
- Before the Act -
Nothing special.
- After the Act -
If a property/field of the instance in expression changed during the Act
(except the property/field in expression), a
SmartTestException is thrown.
Examples
In this example, the Smart Assertion verifies that no property nor field of
other, except
CopyCount,
changed while calling
CopyPropertiesFrom.
[Test]
public void CopyPropertiesFromTest()
{
var mc = new MyClass();
var other = new MyClass();
RunTest( ValidValue.IsValid,
() => mc.CopyPropertiesFrom( other ),
SmartAssert.NotChangedExcept( () => other.CopyCount, NotChangedKind.All ) );
}
See Also