1 | <!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
---|
2 | <html>
|
---|
3 | <!-- Standard Head Part -->
|
---|
4 | <head>
|
---|
5 | <title>NUnit - TypeConstraints</title>
|
---|
6 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
---|
7 | <meta http-equiv="Content-Language" content="en-US">
|
---|
8 | <link rel="stylesheet" type="text/css" href="nunit.css">
|
---|
9 | <link rel="shortcut icon" href="favicon.ico">
|
---|
10 | </head>
|
---|
11 | <!-- End Standard Head Part -->
|
---|
12 |
|
---|
13 | <body>
|
---|
14 |
|
---|
15 | <!-- Standard Header for NUnit.org -->
|
---|
16 | <div id="header">
|
---|
17 | <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
|
---|
18 | <div id="nav">
|
---|
19 | <a href="http://www.nunit.org">NUnit</a>
|
---|
20 | <a class="active" href="index.html">Documentation</a>
|
---|
21 | </div>
|
---|
22 | </div>
|
---|
23 | <!-- End of Header -->
|
---|
24 |
|
---|
25 | <div id="content">
|
---|
26 |
|
---|
27 | <h2>Type Constraints (NUnit 2.4)</h2>
|
---|
28 |
|
---|
29 | <p>Type constraints perform tests that are specific to Types.
|
---|
30 | The following type constraints are provided:
|
---|
31 |
|
---|
32 | <table class="constraints">
|
---|
33 | <tr><th>Syntax Helper</th><th>Constructor</th><th>Operation</th></tr>
|
---|
34 | <tr><td>Is.TypeOf( Type )</td><td>ExactTypeConstraint( Type )</td></td><td>tests that an object is an exact Type</td></tr>
|
---|
35 | <tr><td>Is.InstanceOfType( Type )</td><td>InstanceOfTypeConstraint( Type )</td></td><td>tests that an object is an instance of a Type</td></tr>
|
---|
36 | <tr><td>Is.AssignableFrom( Type )</td><td>AssignableFromConstraint( Type )</td></td><td>tests that one type is assignable from another</td></tr>
|
---|
37 | </table>
|
---|
38 |
|
---|
39 | <h4>Examples of Use</h4>
|
---|
40 |
|
---|
41 | <div class="code"><pre>
|
---|
42 | Assert.That("Hello", Is.TypeOf(typeof(string)));
|
---|
43 | Assert.That("Hello", Is.Not.TypeOf(typeof(int)));
|
---|
44 |
|
---|
45 | Assert.That("Hello", Is.InstanceOfType(typeof(string)));
|
---|
46 | Assert.That(5, Is.Not.InstanceOfType(typeof(string)));
|
---|
47 |
|
---|
48 | Assert.That( "Hello", Is.AssignableFrom(typeof(string)));
|
---|
49 | Assert.That( 5, Is.Not.AssignableFrom(typeof(string)));
|
---|
50 |
|
---|
51 | // Using inheritance
|
---|
52 | Expect( 5, Not.InstanceOfType(typeof(string)));
|
---|
53 | Expect( "Hello", AssignableFrom(typeOf(string)));
|
---|
54 | </pre></div>
|
---|
55 |
|
---|
56 |
|
---|
57 | </div>
|
---|
58 |
|
---|
59 | <!-- Submenu -->
|
---|
60 | <div id="subnav">
|
---|
61 | <ul>
|
---|
62 | <li><a href="index.html">NUnit 2.5.10</a></li>
|
---|
63 | <ul>
|
---|
64 | <li><a href="getStarted.html">Getting Started</a></li>
|
---|
65 | <li><a href="assertions.html">Assertions</a></li>
|
---|
66 | <li><a href="constraintModel.html">Constraints</a></li>
|
---|
67 | <ul>
|
---|
68 | <li><a href="equalConstraint.html">Equal Constraint</a></li>
|
---|
69 | <li><a href="sameasConstraint.html">SameAs Constraint</a></li>
|
---|
70 | <li><a href="conditionConstraints.html">Condition Constraints</a></li>
|
---|
71 | <li><a href="comparisonConstraints.html">Comparison Constrants</a></li>
|
---|
72 | <li><a href="pathConstraints.html">Path Constraints</a></li>
|
---|
73 | <li id="current"><a href="typeConstraints.html">Type Constraints</a></li>
|
---|
74 | <li><a href="stringConstraints.html">String Constraints</a></li>
|
---|
75 | <li><a href="collectionConstraints.html">Collection Constraints</a></li>
|
---|
76 | <li><a href="propertyConstraint.html">Property Constraint</a></li>
|
---|
77 | <li><a href="throwsConstraint.html">Throws Constraint</a></li>
|
---|
78 | <li><a href="compoundConstraints.html">Compound Constraints</a></li>
|
---|
79 | <li><a href="delayedConstraint.html">Delayed Constraint</a></li>
|
---|
80 | <li><a href="listMapper.html">List Mapper</a></li>
|
---|
81 | <li><a href="reusableConstraint.html">Reusable Constraint</a></li>
|
---|
82 | </ul>
|
---|
83 | <li><a href="attributes.html">Attributes</a></li>
|
---|
84 | <li><a href="runningTests.html">Running Tests</a></li>
|
---|
85 | <li><a href="extensibility.html">Extensibility</a></li>
|
---|
86 | <li><a href="releaseNotes.html">Release Notes</a></li>
|
---|
87 | <li><a href="samples.html">Samples</a></li>
|
---|
88 | <li><a href="license.html">License</a></li>
|
---|
89 | </ul>
|
---|
90 | </ul>
|
---|
91 | </div>
|
---|
92 | <!-- End of Submenu -->
|
---|
93 |
|
---|
94 |
|
---|
95 | <!-- Standard Footer for NUnit.org -->
|
---|
96 | <div id="footer">
|
---|
97 | Copyright © 2010 Charlie Poole. All Rights Reserved.
|
---|
98 | </div>
|
---|
99 | <!-- End of Footer -->
|
---|
100 |
|
---|
101 | </body>
|
---|
102 | </html>
|
---|