第 16 页精品文档---下载后可任意编辑c#网络爬虫程序设计 1、Let’sstartwithasimpleexample.Supposewearewritingabankapplicationandwehaveabasicdomainclass–Account.Accountsupportsoperationstodeposit,withdraw,andtransferfunds.TheAccountclassmaylooklikethis:namespacebank{publicclassAccount{privatefloatbalance;publicvoidDeposit(floatamount){balance+=amount;}publicvoidWithdraw(floatamount){balance-=amount;}publicv 2 、 oidTransferFunds(Accountdestination,floatamount){}publicfloatBalance{get{returnbalance;}}}}Nowlet’swriteatestforthisclass–AccountTest.ThefirstmethodwewilltestisTransferFunds.namespacebank{usingNUnit.Framework;[TestFixture]publicclassAccountTest{[Test]publicvoidTransferFunds(){Accountsource=newAccount();source.Deposit(200.00F);Accountdestination=n 3、ewAccount();destination.Deposit(150.00F);source.TransferFunds(destination,100.00F);Assert.AreEqual(250.00F,destination.Balance);Assert.AreEqual(100.00F,source.Balance);}}}Thefirstthingtonoticeaboutthisclassisthatithasa[TestFixture]attributeassociatedwithit–第 17 页精品文档---下载后可任意编辑thisisthewaytoindicatethattheclasscontainstestcode(thisattributecanbeinherited).Theclasshas 4、tobepublicandtherearenorestrictionsonitssuperclass.Theclassalsohastohaveadefaultconstructor.Theonlymethodintheclass–TransferFunds,hasa[Test]attributeassociatedwithit–thisisanindicationthatitisatestmethod.Testmethodshavetoreturnvoidandtakenoparameters.Inourtestmethodwedotheusualinitializationoftherequiredtestobjects,executethetestedbusinessmethoda 5、ndcheckthestateofthebusinessobjects.TheAssertclassdefinesacollectionofmethodsusedtocheckthepost-conditionsandinourexampleweusetheAreEqualmethodtomakesurethatafterthetransferbothaccountshavethecorrectbalances(thereareseveraloverloadingsofthismethod,theversionthatwasusedinthisexamplehasthefollowingparameters:thefirstparameterisanexpectedvalueandthe 6、secondparameteristheactualvalue).Compileandrunthisexample.Assumethatyouhavecompiledyourtestcodeintoabank.dll.StarttheNUnitGu...