QuickStart.doc

c#网络爬虫程序设计

收藏

资源目录
跳过导航链接。
c网络爬虫程序设计.rar
c#网络爬虫程序设计
www.pudn.com.txt
WebSpider_src
Mf
AssemblyInfo.cs
Mf.csproj
Mf.csproj.user
Mf.sln
Mf.suo
Readme.txt
UpgradeLog.XML
Backup
MfService
MfServiceTest
MfServiceVb
MfUtil
NUnit
压缩包内文档预览:
预览图 预览图 预览图 预览图 预览图
编号:148047718    类型:共享资源    大小:5.01MB    格式:RAR    上传时间:2021-10-08 上传人:好资料QQ****51605 IP属地:江苏
20
积分
关 键 词:
c# 网络 爬虫 程序设计
资源描述:
c#网络爬虫程序设计,c#,网络,爬虫,程序设计
内容简介:
Lets start with a simple example. Suppose we are writing a bank application and we have a basic domain class Account. Account supports operations to deposit, withdraw, and transfer funds. The Account class may look like this:namespace bankpublic class Accountprivate float balance;public void Deposit(float amount)balance+=amount;public void Withdraw(float amount)balance-=amount;public void TransferFunds(Account destination, float amount)public float Balanceget return balance;Now lets write a test for this class AccountTest. The first method we will test is TransferFspace bankusing NUnit.Framework;TestFixturepublic class AccountTestTestpublic void TransferFunds()Account source = new Account();source.Deposit(200.00F);Account destination = new Account();destination.Deposit(150.00F);source.TransferFunds(destination, 100.00F);Assert.AreEqual(250.00F, destination.Balance);Assert.AreEqual(100.00F, source.Balance);The first thing to notice about this class is that it has a TestFixture attribute associated with it this is the way to indicate that the class contains test code (this attribute can be inherited). The class has to be public and there are no restrictions on its superclass. The class also has to have a default constructor.The only method in the class TransferFunds, has a Test attribute associated with it this is an indication that it is a test method. Test methods have to return void and take no parameters. In our test method we do the usual initialization of the required test objects, execute the tested business method and check the state of the business objects. The Assert class defines a collection of methods used to check the post-conditions and in our example we use the AreEqual method to make sure that after the transfer both accounts have the correct balances (there are several overloadings of this method, the version that was used in this example has the following parameters : the first parameter is an expected value and the second parameter is the actual value).Compile and run this example. Assume that you have compiled your test code into a bank.dll. Start the NUnit Gui (the installer will have created a shortcut on your desktop and in the “Program Files” folder), after the GUI starts, select the File-Open menu item, navigate to the location of your bank.dll and select it in the “Open” dialog box. When the bank.dll is loaded you will see a test tree structure in the left panel and a collection of status panels on the right. Click the Run button, the status bar and the TransferFunds node in the test tree turn red our test has failed. The “Errors and Failures” panel displayed the following message “TransferFunds : expected but was ” and the stack trace panel right below it reported where in the test code the failure has occurred at bank.AccountTest.TransferFunds() in C:nunitBankSampleTestsAccountTest.cs:line 17”That is expected behavior; the test has failed because we have not implemented the TransferFunds method yet. Now lets get it to work. Dont close the GUI and go back to your IDE and fix the code, make your TransferFunds method look like this:public void TransferFunds(Account destination, float amount)destination.Deposit(amount);Withdraw(amount);Now recompile your code and click the run button in GUI again the status bar and the test tree turn green. (Note how the GUI has reloaded the assembly automatically for you; we will keep the GUI open all the time and continue working with our code in IDE and write more tests).Lets add some error checking to our Account code. We are adding the minimum balance requirement for the account to make sure that banks continue to make their money by charging your minimal overdraft protection fee. Lets add the minimum balance property to our Account class:private float minimumBalance = 10.00F;public float MinimumBalanceget return minimumBalance;We will use an exception to indicate an overdraft:namespace bankusing System;public class InsufficientFundsException : ApplicationExceptionAdd a new test method to our AccountTest class:TestExpectedException(typeof(InsufficientFundsException)public void TransferWithInsufficientFunds()Account source = new Account();source.Deposit(200.00F);Account destination = new Account();destination.Deposit(150.00F);source.TransferFunds(destination, 300.00F);This test method in addition to Test attribute has an ExpectedException attribute associated with it this is the way to indicate that the test code is expecting an exception of a certain type; if such an exception is not thrown during the execution the test will fail. Compile your code and go back to the GUI. As you compiled your test code, the GUI has grayed out and collapsed the test tree as if the tests were not run yet (GUI watches for the changes made to the test assemblies and updates itself when the structure of the test tree has changed e.g. new test is added). Click the “Run” button we have a red status bar again. We got the following Failure : “TransferWithInsufficentFunds : InsufficientFundsException was expected”. Lets fix our Account code again, modify the TransferFunds method this way:public void TransferFunds(Account destination, float amount)destination.Deposit(amount);if(balance-amountminimumBalance)throw new InsufficientFundsException();Withdraw(amount);Compile and run the tests green bar. Success! But wait, looking at the code weve just written we can see that the bank may be loosing money on every unsuccessful funds Transfer operation. Lets write a test to confirm our suspicions. Add this test method:Testpublic void TransferWithInsufficientFundsAtomicity()Account source = new Account();source.Deposit(200.00F);Account destination = new Account();destination.Deposit(150.00F);trysource.TransferFunds(destination, 300.00F);catch(InsufficientFundsException expected)Assert.AreEqual(200.00F,source.Balance);Assert.AreEqual(150.00F,destination.Balance);We are testing the transactional property of our business method all operations are successful or none. Compile and run red bar. OK, weve made $300.00 out of a thin air (1999.com dj vu?) the source account has the correct balance of 150.00 but the destination account shows : $450.00. How do we fix this? Can we just move the minimum balance check call in front of the updates:public void TransferFunds(Account destination, float amount)if(balance-amountminimumBalance) throw new InsufficientFundsException();destination.Deposit(amount);Withdraw(amount);What if the Withdraw() method throws another exception? Should we execute a compensating transaction in the catch block or rely on our transaction manager to restore the state of the objects? We need to answer those questions at some point, but not now; but what do we do with the failing test in the meantime remove it? A better way is to temporarily ignore it, add the following attribute to your test methodTestIgnore(Need to decide how to implement transaction management in the application)public void TransferWithInsufficientFundsAtomicity()/ code is the sameCompile and run yellow bar. Click on “Tests Not Run” tab and you will see bank.AccountTest.TransferWithInsufficientFundsAtomicity() in the list along with the Reason this test is ignored.Looking at our test code we can see that some refactoring is in order. All test methods share a common set of test objects. Lets extract this initialization code into a setup method and reuse it in all of our tests. The refactored version of our test class looks like this:namespace bankusing System;using NUnit.Framework;TestFixturepublic class AccountTestAccount source;Account destination;SetUppublic void Init()source = new Account();source.Deposit(
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
提示  人人文库网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:c#网络爬虫程序设计
链接地址:https://www.renrendoc.com/paper/148047718.html

官方联系方式

2:不支持迅雷下载,请使用浏览器下载   
3:不支持QQ浏览器下载,请用其他浏览器   
4:下载后的文档和图纸-无水印   
5:文档经过压缩,下载后原文更清晰   
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

网站客服QQ:2881952447     

copyright@ 2020-2025  renrendoc.com 人人文库版权所有   联系电话:400-852-1180

备案号:蜀ICP备2022000484号-2       经营许可证: 川B2-20220663       公网安备川公网安备: 51019002004831号

本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知人人文库网,我们立即给予删除!