AssignableTo Constraint
AssignableToConstraint tests that the actual value can be assigned to a variable of the specified type. In other
words, the actual value's type derives from or implements the expected type.
Usage
Is.AssignableTo(Type expectedType)
Is.AssignableTo()
Examples
[Test]
public void AssignableToConstraint_Examples()
{
// A string can be assigned to object (string derives from object)
Assert.That("Hello", Is.AssignableTo(typeof(object)));
Assert.That("Hello", Is.AssignableToNotes
Is.AssignableTois true when() typeof(T).IsAssignableFrom(actual.GetType()).- This tests "can this value be assigned to a variable of type T?".
- This is the reverse of AssignableFromConstraint.
See Also
- AssignableFrom Constraint - Reverse direction check
- InstanceOfType Constraint - Test if object is instance of type
- ExactType Constraint - Test for exact type match