Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; MenuItem has a deprecated constructor in /home/charl422/nunitsoftware.com/nunitv2/php/build_menu.php on line 34
NUnit - TypeConstraints
NUnit 2.5 Legacy Documentation. View NUnit 3 Documentation

Type Constraints (NUnit 2.4)

Type constraints perform tests that are specific to Types. The following type constraints are provided:
Syntax HelperConstructorOperation
Is.TypeOf( Type )ExactTypeConstraint( Type )tests that an object is an exact Type
Is.InstanceOfType( Type )InstanceOfTypeConstraint( Type )tests that an object is an instance of a Type
Is.AssignableFrom( Type )AssignableFromConstraint( Type )tests that one type is assignable from another

Examples of Use

Assert.That("Hello", Is.TypeOf(typeof(string)));
Assert.That("Hello", Is.Not.TypeOf(typeof(int)));

Assert.That("Hello", Is.InstanceOfType(typeof(string)));
Assert.That(5, Is.Not.InstanceOfType(typeof(string)));

Assert.That( "Hello", Is.AssignableFrom(typeof(string)));
Assert.That( 5, Is.Not.AssignableFrom(typeof(string)));

// Using inheritance
Expect( 5, Not.InstanceOfType(typeof(string)));
Expect( "Hello", AssignableFrom(typeOf(string)));