Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet404/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   400   401   402   403   404   405   406   407   ...   453
LISTINg 18-1: 
 Defining a DLL to test
public class Accounts
{
// Contains the current account amount.
private Int32 Total;
public Accounts()
{
// Sets a default acccount amount.
Total = 5000;
}
public Accounts(Int32 Initial)
{
// Set a user supplied initial amount.
Total = Initial;
}
// Provides access to the account total.
public Int32 GetTotal
{
get { return Total; }
}
// Adds a deposit to the account.
public Int32 Deposit
{
set { Total += value; }
}
// Subtracts a withdrawal.
public Int32 Withdrawal
{
set { Total -= value; }
}
public void Transfer(Accounts Account2)
{
// Place the money in the second account in the first account.
this.Total += Account2.Total;
// Withdraw the money from the second account.
Account2.Total = 0;
}
}
548592c18.indd 393
2/24/10 12:49:45 PM
www.finebook.ir


394

CHAPTER 18
Using ironPython for APPlicAtion testing
The example includes two constructors (something you didn’t try in Chapters 16 or 17). The developer 
can create an account with a default value of 
5000
or provide some other initial amount. In either case, 
you end up with a new 
Accounts
object that has 
Total
defined.
The 
GetTotal
property is read-only and lets the developer obtain the total in the count from 
Total

Using a property enables you to perform checks before allowing people to have the information. For 
example, you could place a security code in this property to ensure that only authorized personnel 
received the information. If a developer were to take this approach, you’d need to write a test to check 
the 
GetTotal
property using an account other than the developer account.
The 
Deposit
and 
Withdrawal
properties are write-only. The caller doesn’t receive anything back 
from them. You could use a method to perform the task as well. Using a property makes the test 
code easier to read, but that’s the only advantage. In both cases, the properties change the value of 
Total
. Of course, you can perform checks in the properties, such as verifying that a withdrawal 
won’t result in an account with a value less than 0.
The 
Transfer()
method moves all the money from one account to the other. Typically, you’d provide 
some type of transaction support in a method of this type, but the example doesn’t include it. This is 
one situation where IronPython can test the method’s inputs and outputs, but can’t test the internal 
workings of the method. You’d need another tool to test issues such as whether the transaction support 
actually worked as intended.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   400   401   402   403   404   405   406   407   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish