[Mono-list] Need feedback on NUnit testcase

Krister Hansson ds99krha@thn.htu.se
Tue, 7 May 2002 16:50:53 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_004B_01C1F5E7.599E94A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi there!

=20

I've just begun writing a testcase for System.Convert and got some =
questions since it is my first test.

I would like to sign up to do the test for System.Convert. If it is =
available.

=20

I need some feedback on this code if there is someone who has the time =
to help. (what have I missed, coding conventions and so on.)

What from the specification do I need to test? (Is there anything that =
is more important?)

Do I need to test all the overloaded methods in I.E. =
Convert.ToBoolean()? If not, what should I focus on.



Any help is welcome.

=20

What is preferable, attaching code or pasting code in the mail body?

//Krister



The code

----------------------------------------------

using NUnit.Framework;
using System;
using System.Globalization;

namespace MonoTests.System
{
public class ConvertTest : TestCase
{
public ConvertTest() : base ("MonoTests.System.ConvertTest testsuite") =
{}
public ConvertTest(string name) : base(name) {}

bool tryBool;
byte tryByte;
char tryChar;
DateTime tryDT;
decimal tryDec;
double tryDbl;
short tryInt16;
int tryInt32;
long tryInt64;
object tryObj;
sbyte trySByte;
Single trySngl;
string falseString;
string trueString;
string nullString;
string tryStr;
ushort tryUI16;
uint tryUI32;
ulong tryUI64;
CultureInfo ci;

protected override void SetUp() {
tryBool =3D true;
tryByte =3D 0;
tryChar =3D 'a';
tryDT =3D new DateTime(2002,5,7);
tryDec =3D 1234.2345m;
tryDbl =3D 0;
tryInt16 =3D 1234;
tryInt32 =3D 12345678;
tryInt64 =3D 123456789012;
tryObj =3D (object)tryDbl;
trySByte =3D 123;
trySngl =3D 1234.2345f;
falseString =3D "false";
trueString =3D "true";
nullString =3D null;
tryStr =3D "foobar";
tryUI16 =3D 34567;
tryUI32 =3D 567891234;
tryUI64 =3D 0;
ci =3D new CultureInfo("sv-SE");
ci.NumberFormat.NumberDecimalDigits =3D 3;
}
protected override void TearDown() {}
public static ITest Suite {
get {=20
return new TestSuite(typeof(ConvertTest));=20
}
}
public void TestChangeType() {
TypeCode tcInt16 =3D new Int16().GetTypeCode();

AssertEquals("#A01", new short().GetType(),=20
Convert.ChangeType(tryInt32, tcInt16).GetType());=20
AssertEquals("#A02", 'A', Convert.ChangeType(65, typeof(char)));
AssertEquals("#A03", 66, Convert.ChangeType('B', typeof(int)));=20
try {
Convert.ChangeType(myBool, typeof(char));
}
catch (Exception e) {
AssertEquals("ChangeType should be a InvalidCastException",=20
typeof(InvalidCastException), e.GetType());
}

try {
Convert.ChangeType(myBool, null);
}
catch (Exception e) {
AssertEquals("ChangeType should be a ArgumentNullException",=20
typeof(ArgumentNullException), e.GetType());
}
}=20

public void TestGetTypeCode()=20
{
TypeCode tc1 =3D new Int32().GetTypeCode();
TypeCode tc2 =3D new Boolean().GetTypeCode();
int tcInt32 =3D 1234;
bool tcBool =3D true;
AssertEquals("#B01", tc1, tcInt32.GetTypeCode());
AssertEquals("#B02", tc2, tcBool.GetTypeCode());
}
public void TestIsDBNull() {
DBNull db =3D (DBNull)Convert.DBNull;
int dbNullInt =3D 1234;

AssertEquals("#C01", false, Convert.IsDBNull(dbNullInt));
AssertEquals("#C02", true, Convert.IsDBNull(db));
}

public void TestToBoolean() {

AssertEquals("#D01", true, Convert.ToBoolean(tryBool));
AssertEquals("#D02", false, Convert.ToBoolean(tryByte));

try {
Convert.ToBoolean(tryChar);
}
catch (Exception e) {
AssertEquals("#D03 should throw a InvalidCastException",=20
typeof(InvalidCastException), e.GetType());
}

try {
Convert.ToBoolean(tryDT);
}
catch (Exception e) {
AssertEquals("#D04 should throw a InvalidCastException",=20
typeof(InvalidCastException), e.GetType());
}
AssertEquals("#D05", true, Convert.ToBoolean(tryDec));
AssertEquals("#D06", false, Convert.ToBoolean(tryDbl));
AssertEquals("#D07", true, Convert.ToBoolean(tryInt16));
AssertEquals("#D08", true, Convert.ToBoolean(tryInt32));
AssertEquals("#D09", true, Convert.ToBoolean(tryInt64));
AssertEquals("#D10", false, Convert.ToBoolean(tryObj));
AssertEquals("#D11", true, Convert.ToBoolean(trySByte));
AssertEquals("#D12", true, Convert.ToBoolean(trySngl));
AssertEquals("#D13", true, Convert.ToBoolean(trueString));
AssertEquals("#D14", false, Convert.ToBoolean(falseString));
try {
Convert.ToBoolean(tryStr);
}
catch (Exception e) {
AssertEquals("#D15 should throw a FormatException",=20
typeof(FormatException), e.GetType());
}
try {
Convert.ToBoolean(nullString);
}
catch (Exception e) {
AssertEquals("#D16 should throw a ArgumentNullException",=20
typeof(ArgumentNullException), e.GetType());
}
AssertEquals("#D17", true, Convert.ToBoolean(tryUI16));
AssertEquals("#D18", true, Convert.ToBoolean(tryUI32));
AssertEquals("#D19", false, Convert.ToBoolean(tryUI64));
AssertEquals("#D20", false, Convert.ToBoolean(tryObj,ci));
AssertEquals("#D21", false, Convert.ToBoolean(tryObj));

}
}
}

--------------------------------------------------------------------

------=_NextPart_000_004B_01C1F5E7.599E94A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2715.400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff><FONT face=3DArial size=3D2>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB">Hi=20
there!</SPAN><SPAN lang=3DEN-GB style=3D"mso-ansi-language: =
EN-GB"><?xml:namespace=20
prefix =3D o ns =3D "urn:schemas-microsoft-com:office:office"=20
/><o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"mso-ansi-language: EN-GB"><FONT size=3D3><FONT=20
face=3D"Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB">I've just=20
begun writing a testcase for System.Convert and got some questions since =
it is=20
my first test.</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB">I would=20
like to sign up to do the test for System.Convert. If it is=20
available.</SPAN><SPAN lang=3DEN-GB=20
style=3D"mso-ansi-language: EN-GB"><o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"mso-ansi-language: EN-GB"><FONT size=3D3><FONT=20
face=3D"Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB">I need=20
some feedback on this code if there is someone who has the time to help. =
(what=20
have I missed, coding conventions and so on.)</SPAN><SPAN lang=3DEN-GB=20
style=3D"mso-ansi-language: EN-GB"><o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB">What from=20
the specification do I need to test? (Is there anything that is more=20
important?)</SPAN><SPAN lang=3DEN-GB=20
style=3D"mso-ansi-language: EN-GB"><o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB">Do I need=20
to test all the overloaded methods in I.E. Convert.ToBoolean()? If not, =
what=20
should I focus on.</SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB"></SPAN>&nbsp;</P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: =
EN-GB">Any help=20
is welcome.</SPAN><SPAN lang=3DEN-GB=20
style=3D"mso-ansi-language: EN-GB"><o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN lang=3DEN-GB=20
style=3D"mso-ansi-language: EN-GB"><FONT size=3D3><FONT=20
face=3D"Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></SPAN></P>
<DIV><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: EN-GB; =
mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: SV; =
mso-bidi-language: AR-SA">What=20
is preferable, attaching code or pasting code in the mail =
body?</SPAN></DIV>
<DIV><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: EN-GB; =
mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: SV; =
mso-bidi-language: AR-SA"></SPAN>&nbsp;</DIV>
<DIV><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: EN-GB; =
mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: SV; =
mso-bidi-language: AR-SA">//Krister</SPAN></DIV>
<DIV><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: EN-GB; =
mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: SV; =
mso-bidi-language: AR-SA"></SPAN>&nbsp;</DIV>
<DIV><SPAN lang=3DEN-GB=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-ansi-language: EN-GB; =
mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: SV; =
mso-bidi-language: AR-SA"></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The code</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT =
color=3D#0000ff size=3D2>
<DIV><FONT face=3DArial color=3D#000000>using</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> NUnit.Framework;</FONT></DIV></FONT><FONT color=3D#0000ff =
size=3D2>
<DIV><FONT face=3DArial color=3D#000000>using</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> System;</FONT></DIV></FONT><FONT color=3D#0000ff size=3D2>
<DIV><FONT face=3DArial color=3D#000000>using</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> System.Globalization;</FONT></FONT></DIV>
<DIV><FONT size=3D2>&nbsp;</DIV></FONT><FONT color=3D#0000ff size=3D2>
<DIV><FONT face=3DArial color=3D#000000>namespace</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> MonoTests.System</FONT></DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>class</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> ConvertTest : TestCase</FONT></DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT=20
size=3D2> ConvertTest() : </FONT><FONT color=3D#0000ff=20
size=3D2>base</FONT></FONT><FONT size=3D2><FONT face=3DArial>=20
("MonoTests.System.ConvertTest testsuite") {}</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT=20
size=3D2> ConvertTest(</FONT><FONT color=3D#0000ff =
size=3D2>string</FONT><FONT size=3D2>=20
name) : </FONT><FONT color=3D#0000ff size=3D2>base</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial>(name) {}</FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>bool</FONT><FONT =
size=3D2><FONT=20
face=3DArial> tryBool;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>byte</FONT><FONT =
size=3D2><FONT=20
face=3DArial> tryByte;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>char</FONT><FONT =
size=3D2><FONT=20
face=3DArial> tryChar;</FONT></DIV>
<DIV><FONT face=3DArial>DateTime tryDT;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>decimal</FONT><FONT=20
size=3D2><FONT face=3DArial> tryDec;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>double</FONT><FONT=20
size=3D2><FONT face=3DArial> tryDbl;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>short</FONT><FONT size=3D2><FONT=20
face=3DArial> tryInt16;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>int</FONT><FONT =
size=3D2><FONT=20
face=3DArial> tryInt32;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>long</FONT><FONT =
size=3D2><FONT=20
face=3DArial> tryInt64;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>object</FONT><FONT=20
size=3D2><FONT face=3DArial> tryObj;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>sbyte</FONT><FONT size=3D2><FONT=20
face=3DArial> trySByte;</FONT></DIV>
<DIV><FONT face=3DArial>Single trySngl;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>string</FONT><FONT=20
size=3D2><FONT face=3DArial> falseString;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>string</FONT><FONT=20
size=3D2><FONT face=3DArial> trueString;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>string</FONT><FONT=20
size=3D2><FONT face=3DArial> nullString;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>string</FONT><FONT=20
size=3D2><FONT face=3DArial> tryStr;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>ushort</FONT><FONT=20
size=3D2><FONT face=3DArial> tryUI16;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>uint</FONT><FONT =
size=3D2><FONT=20
face=3DArial> tryUI32;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>ulong</FONT><FONT size=3D2><FONT=20
face=3DArial> tryUI64;</FONT></DIV>
<DIV><FONT face=3DArial>CultureInfo ci;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>protected</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>override</FONT><FONT =
size=3D2>=20
</FONT><FONT color=3D#0000ff size=3D2>void</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> SetUp() {</FONT></DIV>
<DIV><FONT face=3DArial>tryBool =3D </FONT></FONT><FONT face=3DArial =
color=3D#0000ff=20
size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>;</FONT></DIV>
<DIV><FONT face=3DArial>tryByte =3D 0;</FONT></DIV>
<DIV><FONT face=3DArial>tryChar =3D 'a';</FONT></DIV>
<DIV><FONT face=3DArial>tryDT =3D </FONT></FONT><FONT face=3DArial =
color=3D#0000ff=20
size=3D2>new</FONT><FONT size=3D2><FONT face=3DArial> =
DateTime(2002,5,7);</FONT></DIV>
<DIV><FONT face=3DArial>tryDec =3D 1234.2345m;</FONT></DIV>
<DIV><FONT face=3DArial>tryDbl =3D 0;</FONT></DIV>
<DIV><FONT face=3DArial>tryInt16 =3D 1234;</FONT></DIV>
<DIV><FONT face=3DArial>tryInt32 =3D 12345678;</FONT></DIV>
<DIV><FONT face=3DArial>tryInt64 =3D 123456789012;</FONT></DIV>
<DIV><FONT face=3DArial>tryObj =3D (</FONT></FONT><FONT face=3DArial =
color=3D#0000ff=20
size=3D2>object</FONT><FONT size=3D2><FONT =
face=3DArial>)tryDbl;</FONT></DIV>
<DIV><FONT face=3DArial>trySByte =3D 123;</FONT></DIV>
<DIV><FONT face=3DArial>trySngl =3D 1234.2345f;</FONT></DIV>
<DIV><FONT face=3DArial>falseString =3D "false";</FONT></DIV>
<DIV><FONT face=3DArial>trueString =3D "true";</FONT></DIV>
<DIV><FONT face=3DArial>nullString =3D </FONT></FONT><FONT face=3DArial =
color=3D#0000ff=20
size=3D2>null</FONT><FONT size=3D2><FONT face=3DArial>;</FONT></DIV>
<DIV><FONT face=3DArial>tryStr =3D "foobar";</FONT></DIV>
<DIV><FONT face=3DArial>tryUI16 =3D 34567;</FONT></DIV>
<DIV><FONT face=3DArial>tryUI32 =3D 567891234;</FONT></DIV>
<DIV><FONT face=3DArial>tryUI64 =3D 0;</FONT></DIV>
<DIV><FONT face=3DArial>ci =3D </FONT></FONT><FONT face=3DArial =
color=3D#0000ff=20
size=3D2>new</FONT><FONT size=3D2><FONT face=3DArial>=20
CultureInfo("sv-SE");</FONT></DIV>
<DIV><FONT face=3DArial>ci.NumberFormat.NumberDecimalDigits =3D =
3;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>protected</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>override</FONT><FONT =
size=3D2>=20
</FONT><FONT color=3D#0000ff size=3D2>void</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> TearDown() {}</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff =
size=3D2>static</FONT></FONT><FONT size=3D2><FONT=20
face=3DArial> ITest Suite {</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>get</FONT><FONT =
size=3D2><FONT=20
face=3DArial> {</FONT> </DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>return</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>new</FONT><FONT =
size=3D2>=20
TestSuite(</FONT><FONT color=3D#0000ff =
size=3D2>typeof</FONT></FONT><FONT=20
size=3D2><FONT face=3DArial>(ConvertTest));</FONT> </DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>void</FONT><FONT =
size=3D2>=20
TestChangeType() {</DIV></FONT></FONT><FONT size=3D2><FONT =
face=3DArial><FONT=20
size=3D2>
<DIV>TypeCode tcInt16 =3D </FONT><FONT color=3D#0000ff =
size=3D2>new</FONT><FONT=20
size=3D2> Int16().GetTypeCode();</DIV>
<DIV>&nbsp;</DIV>
<DIV>AssertEquals("#A01", </FONT><FONT color=3D#0000ff =
size=3D2>new</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>short</FONT><FONT =
size=3D2>().GetType(),=20
</DIV>
<DIV>Convert.ChangeType(tryInt32, tcInt16).GetType()); </DIV>
<DIV>AssertEquals("#A02", 'A', Convert.ChangeType(65, </FONT><FONT =
color=3D#0000ff=20
size=3D2>typeof</FONT><FONT size=3D2>(</FONT><FONT color=3D#0000ff=20
size=3D2>char</FONT><FONT size=3D2>)));</DIV>
<DIV>AssertEquals("#A03", 66, Convert.ChangeType('B', </FONT><FONT =
color=3D#0000ff=20
size=3D2>typeof</FONT><FONT size=3D2>(</FONT><FONT color=3D#0000ff=20
size=3D2>int</FONT><FONT size=3D2>))); </DIV></FONT></FONT></FONT><FONT =
size=3D2>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>try</FONT><FONT =
size=3D2><FONT=20
face=3DArial> {</FONT></DIV>
<DIV><FONT face=3DArial>Convert.ChangeType(myBool, </FONT></FONT><FONT=20
face=3DArial><FONT color=3D#0000ff size=3D2>typeof</FONT><FONT =
size=3D2>(</FONT><FONT=20
color=3D#0000ff size=3D2>char</FONT></FONT><FONT size=3D2><FONT=20
face=3DArial>));</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>catch</FONT><FONT size=3D2><FONT=20
face=3DArial> (Exception e) {</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("ChangeType should be a=20
InvalidCastException",</FONT> </DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>typeof</FONT><FONT=20
size=3D2><FONT face=3DArial>(InvalidCastException), =
e.GetType());</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>try</FONT><FONT =
size=3D2><FONT=20
face=3DArial> {</FONT></DIV>
<DIV><FONT face=3DArial>Convert.ChangeType(myBool, </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>null</FONT><FONT size=3D2><FONT =
face=3DArial>);</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>catch</FONT><FONT size=3D2><FONT=20
face=3DArial> (Exception e) {</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("ChangeType should be a=20
ArgumentNullException",</FONT> </DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>typeof</FONT><FONT=20
size=3D2><FONT face=3DArial>(ArgumentNullException), =
e.GetType());</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT> </DIV>
<DIV></FONT><FONT face=3DArial color=3D#008000 size=3D2></FONT><FONT =
color=3D#008000=20
size=3D2><FONT face=3DArial></FONT>&nbsp;</DIV></FONT><FONT size=3D2>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>void</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> TestGetTypeCode()</FONT> </DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial>TypeCode tc1 =3D </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>new</FONT><FONT size=3D2><FONT face=3DArial>=20
Int32().GetTypeCode();</FONT></DIV>
<DIV><FONT face=3DArial>TypeCode tc2 =3D </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>new</FONT><FONT size=3D2><FONT face=3DArial>=20
Boolean().GetTypeCode();</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>int</FONT><FONT =
size=3D2><FONT=20
face=3DArial> tcInt32 =3D 1234;</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>bool</FONT><FONT size=3D2>=20
tcBool =3D </FONT><FONT color=3D#0000ff size=3D2>true</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial>;</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#B01", tc1,=20
tcInt32.GetTypeCode());</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#B02", tc2,=20
tcBool.GetTypeCode());</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT=20
size=3D2> </FONT><FONT color=3D#0000ff size=3D2>void</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> TestIsDBNull() {</FONT></DIV>
<DIV><FONT face=3DArial>DBNull db =3D =
(DBNull)Convert.DBNull;</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>int</FONT><FONT =
size=3D2><FONT=20
face=3DArial> dbNullInt =3D 1234;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial>AssertEquals("#C01", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.IsDBNull(dbNullInt));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#C02", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.IsDBNull(db));</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV></FONT><FONT size=3D2>
<DIV></FONT><FONT face=3DArial><FONT color=3D#0000ff=20
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT color=3D#0000ff =
size=3D2>public</FONT><FONT size=3D2>=20
</FONT><FONT color=3D#0000ff size=3D2>void</FONT></FONT><FONT =
size=3D2><FONT=20
face=3DArial> TestToBoolean() {</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial>AssertEquals("#D01", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(tryBool));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D02", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.ToBoolean(tryByte));</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>try</FONT><FONT =
size=3D2><FONT=20
face=3DArial> {</FONT></DIV>
<DIV><FONT face=3DArial>Convert.ToBoolean(tryChar);</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>catch</FONT><FONT size=3D2><FONT=20
face=3DArial> (Exception e) {</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D03 should throw a=20
InvalidCastException",</FONT> </DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>typeof</FONT><FONT=20
size=3D2><FONT face=3DArial>(InvalidCastException), =
e.GetType());</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>try</FONT><FONT =
size=3D2><FONT=20
face=3DArial> {</FONT></DIV>
<DIV><FONT face=3DArial>Convert.ToBoolean(tryDT);</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>catch</FONT><FONT size=3D2><FONT=20
face=3DArial> (Exception e) {</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D04 should throw a=20
InvalidCastException",</FONT> </DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>typeof</FONT><FONT=20
size=3D2><FONT face=3DArial>(InvalidCastException), =
e.GetType());</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D05", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(tryDec));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D06", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.ToBoolean(tryDbl));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D07", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(tryInt16));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D08", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(tryInt32));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D09", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(tryInt64));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D10", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.ToBoolean(tryObj));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D11", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(trySByte));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D12", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(trySngl));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D13", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(trueString));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D14", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.ToBoolean(falseString));</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>try</FONT><FONT =
size=3D2><FONT=20
face=3DArial> {</FONT></DIV>
<DIV><FONT face=3DArial>Convert.ToBoolean(tryStr);</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>catch</FONT><FONT size=3D2><FONT=20
face=3DArial> (Exception e) {</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D15 should throw a =
FormatException",</FONT>=20
</DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>typeof</FONT><FONT=20
size=3D2><FONT face=3DArial>(FormatException), =
e.GetType());</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff size=3D2>try</FONT><FONT =
size=3D2><FONT=20
face=3DArial> {</FONT></DIV>
<DIV><FONT face=3DArial>Convert.ToBoolean(nullString);</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>catch</FONT><FONT size=3D2><FONT=20
face=3DArial> (Exception e) {</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D16 should throw a=20
ArgumentNullException",</FONT> </DIV>
<DIV></FONT><FONT face=3DArial color=3D#0000ff =
size=3D2>typeof</FONT><FONT=20
size=3D2><FONT face=3DArial>(ArgumentNullException), =
e.GetType());</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D17", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(tryUI16));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D18", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>true</FONT><FONT size=3D2><FONT face=3DArial>,=20
Convert.ToBoolean(tryUI32));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D19", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.ToBoolean(tryUI64));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D20", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.ToBoolean(tryObj,ci));</FONT></DIV>
<DIV><FONT face=3DArial>AssertEquals("#D21", </FONT></FONT><FONT =
face=3DArial=20
color=3D#0000ff size=3D2>false</FONT><FONT size=3D2><FONT face=3DArial>, =

Convert.ToBoolean(tryObj));</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT=20
face=3DArial>------------------------------------------------------------=
--------</FONT></DIV></FONT></BODY></HTML>

------=_NextPart_000_004B_01C1F5E7.599E94A0--