~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to doc/quickStartSource.html

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
 
2
<html>
 
3
<!-- Standard Head Part -->
 
4
<head>
 
5
<title>NUnit - QuickStartSource</title>
 
6
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
 
7
<meta http-equiv="Content-Language" content="en-US">
 
8
<meta name="norton-safeweb-site-verification" content="tb6xj01p4hgo5x-8wscsmq633y11-e6nhk-bnb5d987bseanyp6p0uew-pec8j963qlzj32k5x9h3r2q7wh-vmy8bbhek5lnpp5w4p8hocouuq39e09jrkihdtaeknua" />
 
9
<link rel="stylesheet" type="text/css" href="nunit.css">
 
10
<link rel="shortcut icon" href="favicon.ico">
 
11
</head>
 
12
<!-- End Standard Head Part -->
 
13
 
 
14
<body>
 
15
 
 
16
<!-- Standard Header for NUnit.org -->
 
17
<div id="header">
 
18
  <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
 
19
  <div id="nav">
 
20
    <a href="http://www.nunit.org">NUnit</a>
 
21
    <a class="active" href="index.html">Documentation</a>
 
22
  </div>
 
23
</div>
 
24
<!-- End of Header -->
 
25
 
 
26
<div id="content">
 
27
 
 
28
<style><!--
 
29
  div.code { width: 34em }
 
30
--></style>
 
31
 
 
32
<h2>NUnit Quick Start</h2>
 
33
 
 
34
<div class="code">
 
35
<pre>using System;
 
36
using NUnit.Framework;
 
37
 
 
38
namespace Bank
 
39
{
 
40
  public class Account
 
41
  {
 
42
    private decimal balance;
 
43
    private decimal minimumBalance = 10m;
 
44
 
 
45
    public void Deposit(decimal amount)
 
46
    {
 
47
      balance += amount;
 
48
    }
 
49
 
 
50
    public void Withdraw(decimal amount)
 
51
    {
 
52
      balance -= amount;
 
53
    }
 
54
 
 
55
    public void TransferFunds(Account destination, decimal amount)
 
56
    {
 
57
      if (balance - amount < minimumBalance)
 
58
        throw new InsufficientFundsException();
 
59
 
 
60
      destination.Deposit(amount);
 
61
 
 
62
      Withdraw(amount);
 
63
    }
 
64
 
 
65
    public decimal Balance
 
66
    {
 
67
      get { return balance; }
 
68
    }
 
69
 
 
70
    public decimal MinimumBalance
 
71
    {
 
72
      get { return minimumBalance; }
 
73
    }
 
74
  }
 
75
 
 
76
  public class InsufficientFundsException : ApplicationException
 
77
  {
 
78
  }
 
79
 
 
80
  [TestFixture]
 
81
  public class AccountTest
 
82
  {
 
83
    Account source;
 
84
    Account destination;
 
85
 
 
86
    [SetUp]
 
87
    public void Init()
 
88
    {
 
89
      source = new Account();
 
90
      source.Deposit(200m);
 
91
 
 
92
      destination = new Account();
 
93
      destination.Deposit(150m);
 
94
    }
 
95
 
 
96
    [Test]
 
97
    public void TransferFunds()
 
98
    {
 
99
      source.TransferFunds(destination, 100m);
 
100
 
 
101
      Assert.AreEqual(250m, destination.Balance);
 
102
      Assert.AreEqual(100m, source.Balance);
 
103
    }
 
104
 
 
105
    [Test]
 
106
    [ExpectedException(typeof(InsufficientFundsException))]
 
107
    public void TransferWithInsufficientFunds()
 
108
    {
 
109
      source.TransferFunds(destination, 300m);
 
110
    }
 
111
 
 
112
    [Test]
 
113
    [Ignore("Decide how to implement transaction management")]
 
114
    public void TransferWithInsufficientFundsAtomicity()
 
115
    {
 
116
      try
 
117
      {
 
118
        source.TransferFunds(destination, 300m);
 
119
      }
 
120
      catch (InsufficientFundsException expected)
 
121
      {
 
122
      }
 
123
 
 
124
      Assert.AreEqual(200m, source.Balance);
 
125
      Assert.AreEqual(150m, destination.Balance);
 
126
    }
 
127
  }
 
128
}</pre>
 
129
</div>
 
130
<div style="width: 34em; text-align:center;">
 
131
<b>Listing - QuickStart Example</b>
 
132
</div>
 
133
 
 
134
 
 
135
</div>
 
136
 
 
137
<!-- Submenu -->
 
138
<div id="subnav">
 
139
<ul>
 
140
<li><a href="index.html">NUnit 2.6.3</a></li>
 
141
<ul>
 
142
<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
 
143
<ul>
 
144
<li><a href="quickStart.html">Quick&nbsp;Start</a></li>
 
145
<ul>
 
146
<li id="current"><a href="quickStartSource.html">Source&nbsp;Listing</a></li>
 
147
</ul>
 
148
<li><a href="installation.html">Installation</a></li>
 
149
</ul>
 
150
<li><a href="writingTests.html">Writing&nbsp;Tests</a></li>
 
151
<li><a href="runningTests.html">Running&nbsp;Tests</a></li>
 
152
<li><a href="extensibility.html">Extensibility</a></li>
 
153
<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
 
154
<li><a href="samples.html">Samples</a></li>
 
155
<li><a href="license.html">License</a></li>
 
156
</ul>
 
157
<li><a href="vsTestAdapter.html">NUnit&nbsp;Test&nbsp;Adapter</a></li>
 
158
<ul>
 
159
<li><a href="vsTestAdapterLicense.html">License</a></li>
 
160
<li><a href="vsTestAdapterReleaseNotes.html">Release&nbsp;Notes</a></li>
 
161
</ul>
 
162
<li><a href="&r=2.6.3.html"></a></li>
 
163
<li><a href="&r=2.6.3.html"></a></li>
 
164
</ul>
 
165
</div>
 
166
<!-- End of Submenu -->
 
167
 
 
168
 
 
169
<!-- Standard Footer for NUnit.org -->
 
170
<div id="footer">
 
171
  Copyright &copy; 2012 Charlie Poole. All Rights Reserved.
 
172
</div>
 
173
<!-- End of Footer -->
 
174
 
 
175
</body>
 
176
</html>