177 lines
4.1 KiB
HTML
177 lines
4.1 KiB
HTML
<!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
|
<html>
|
|
<!-- Standard Head Part -->
|
|
<head>
|
|
<title>NUnit - QuickStartSource</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
|
<meta http-equiv="Content-Language" content="en-US">
|
|
<meta name="norton-safeweb-site-verification" content="tb6xj01p4hgo5x-8wscsmq633y11-e6nhk-bnb5d987bseanyp6p0uew-pec8j963qlzj32k5x9h3r2q7wh-vmy8bbhek5lnpp5w4p8hocouuq39e09jrkihdtaeknua" />
|
|
<link rel="stylesheet" type="text/css" href="nunit.css">
|
|
<link rel="shortcut icon" href="favicon.ico">
|
|
</head>
|
|
<!-- End Standard Head Part -->
|
|
|
|
<body>
|
|
|
|
<!-- Standard Header for NUnit.org -->
|
|
<div id="header">
|
|
<a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
|
|
<div id="nav">
|
|
<a href="http://www.nunit.org">NUnit</a>
|
|
<a class="active" href="index.html">Documentation</a>
|
|
</div>
|
|
</div>
|
|
<!-- End of Header -->
|
|
|
|
<div id="content">
|
|
|
|
<style><!--
|
|
div.code { width: 34em }
|
|
--></style>
|
|
|
|
<h2>NUnit Quick Start</h2>
|
|
|
|
<div class="code">
|
|
<pre>using System;
|
|
using NUnit.Framework;
|
|
|
|
namespace Bank
|
|
{
|
|
public class Account
|
|
{
|
|
private decimal balance;
|
|
private decimal minimumBalance = 10m;
|
|
|
|
public void Deposit(decimal amount)
|
|
{
|
|
balance += amount;
|
|
}
|
|
|
|
public void Withdraw(decimal amount)
|
|
{
|
|
balance -= amount;
|
|
}
|
|
|
|
public void TransferFunds(Account destination, decimal amount)
|
|
{
|
|
if (balance - amount < minimumBalance)
|
|
throw new InsufficientFundsException();
|
|
|
|
destination.Deposit(amount);
|
|
|
|
Withdraw(amount);
|
|
}
|
|
|
|
public decimal Balance
|
|
{
|
|
get { return balance; }
|
|
}
|
|
|
|
public decimal MinimumBalance
|
|
{
|
|
get { return minimumBalance; }
|
|
}
|
|
}
|
|
|
|
public class InsufficientFundsException : ApplicationException
|
|
{
|
|
}
|
|
|
|
[TestFixture]
|
|
public class AccountTest
|
|
{
|
|
Account source;
|
|
Account destination;
|
|
|
|
[SetUp]
|
|
public void Init()
|
|
{
|
|
source = new Account();
|
|
source.Deposit(200m);
|
|
|
|
destination = new Account();
|
|
destination.Deposit(150m);
|
|
}
|
|
|
|
[Test]
|
|
public void TransferFunds()
|
|
{
|
|
source.TransferFunds(destination, 100m);
|
|
|
|
Assert.AreEqual(250m, destination.Balance);
|
|
Assert.AreEqual(100m, source.Balance);
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException(typeof(InsufficientFundsException))]
|
|
public void TransferWithInsufficientFunds()
|
|
{
|
|
source.TransferFunds(destination, 300m);
|
|
}
|
|
|
|
[Test]
|
|
[Ignore("Decide how to implement transaction management")]
|
|
public void TransferWithInsufficientFundsAtomicity()
|
|
{
|
|
try
|
|
{
|
|
source.TransferFunds(destination, 300m);
|
|
}
|
|
catch (InsufficientFundsException expected)
|
|
{
|
|
}
|
|
|
|
Assert.AreEqual(200m, source.Balance);
|
|
Assert.AreEqual(150m, destination.Balance);
|
|
}
|
|
}
|
|
}</pre>
|
|
</div>
|
|
<div style="width: 34em; text-align:center;">
|
|
<b>Listing - QuickStart Example</b>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<!-- Submenu -->
|
|
<div id="subnav">
|
|
<ul>
|
|
<li><a href="index.html">NUnit 2.6.3</a></li>
|
|
<ul>
|
|
<li><a href="getStarted.html">Getting Started</a></li>
|
|
<ul>
|
|
<li><a href="quickStart.html">Quick Start</a></li>
|
|
<ul>
|
|
<li id="current"><a href="quickStartSource.html">Source Listing</a></li>
|
|
</ul>
|
|
<li><a href="installation.html">Installation</a></li>
|
|
</ul>
|
|
<li><a href="writingTests.html">Writing Tests</a></li>
|
|
<li><a href="runningTests.html">Running Tests</a></li>
|
|
<li><a href="extensibility.html">Extensibility</a></li>
|
|
<li><a href="releaseNotes.html">Release Notes</a></li>
|
|
<li><a href="samples.html">Samples</a></li>
|
|
<li><a href="license.html">License</a></li>
|
|
</ul>
|
|
<li><a href="vsTestAdapter.html">NUnit Test Adapter</a></li>
|
|
<ul>
|
|
<li><a href="vsTestAdapterLicense.html">License</a></li>
|
|
<li><a href="vsTestAdapterReleaseNotes.html">Release Notes</a></li>
|
|
</ul>
|
|
<li><a href="&r=2.6.3.html"></a></li>
|
|
<li><a href="&r=2.6.3.html"></a></li>
|
|
</ul>
|
|
</div>
|
|
<!-- End of Submenu -->
|
|
|
|
|
|
<!-- Standard Footer for NUnit.org -->
|
|
<div id="footer">
|
|
Copyright © 2012 Charlie Poole. All Rights Reserved.
|
|
</div>
|
|
<!-- End of Footer -->
|
|
|
|
</body>
|
|
</html>
|