Type constraints perform tests that are specific to Types. The following type constraints are provided:
Syntax Helper | Constructor | Operation |
---|---|---|
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 |
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)));