-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
125 lines (101 loc) · 6.08 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>NSubstitute: A friendly substitute for .NET mocking libraries</title>
<link rel="stylesheet" href="/css/style.css" type="text/css" />
<script src="/js/scripts.js"></script>
</head>
<body>
<div id="header">
<a href="/" alt="NSubstitute">
<img src="/images/nsubstitute-100x100.png" style="float: left; margin-right: 15px; width: 100px; height: 100px;" />
<h1 class="copy-disabled" style="display: inline"> NSubstitute </h1> <br />
<span><i>A friendly substitute for .NET mocking libraries</i></span>
</a>
</div>
<div id="nav">
<a href="/help/getting-started">Get started</a> |
<a href="/help.html">Docs and getting help</a> |
<a href="https://github.com/nsubstitute/NSubstitute">NSub on GitHub</a>
</div>
<div id="content">
<div id="features">
<div class="feature">
<a id="simple_succinct_pleasant_to_use"></a>
<h2 id="simple-succinct-pleasant-to-use">Simple, succinct, pleasant to use</h2>
<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">//Create:</span>
<span class="kt">var</span> <span class="n">calculator</span> <span class="p">=</span> <span class="n">Substitute</span><span class="p">.</span><span class="n">For</span><span class="p"><</span><span class="n">ICalculator</span><span class="p">>();</span>
<span class="c1">//Set a return value:</span>
<span class="n">calculator</span><span class="p">.</span><span class="nf">Add</span><span class="p">(</span><span class="m">1</span><span class="p">,</span> <span class="m">2</span><span class="p">).</span><span class="nf">Returns</span><span class="p">(</span><span class="m">3</span><span class="p">);</span>
<span class="n">Assert</span><span class="p">.</span><span class="nf">AreEqual</span><span class="p">(</span><span class="m">3</span><span class="p">,</span> <span class="n">calculator</span><span class="p">.</span><span class="nf">Add</span><span class="p">(</span><span class="m">1</span><span class="p">,</span> <span class="m">2</span><span class="p">));</span>
<span class="c1">//Check received calls:</span>
<span class="n">calculator</span><span class="p">.</span><span class="nf">Received</span><span class="p">().</span><span class="nf">Add</span><span class="p">(</span><span class="m">1</span><span class="p">,</span> <span class="n">Arg</span><span class="p">.</span><span class="n">Any</span><span class="p"><</span><span class="kt">int</span><span class="p">>());</span>
<span class="n">calculator</span><span class="p">.</span><span class="nf">DidNotReceive</span><span class="p">().</span><span class="nf">Add</span><span class="p">(</span><span class="m">2</span><span class="p">,</span> <span class="m">2</span><span class="p">);</span>
<span class="c1">//Raise events</span>
<span class="n">calculator</span><span class="p">.</span><span class="n">PoweringUp</span> <span class="p">+=</span> <span class="n">Raise</span><span class="p">.</span><span class="nf">Event</span><span class="p">();</span>
</code></pre></div> </div>
<!--
```requiredcode
public interface ICalculator
{
int Add(int a, int b);
string Mode { get; set; }
event EventHandler PoweringUp;
}
```
-->
</div>
<div class="feature">
<a id="helpful_exceptions"></a>
<h2 id="helpful-exceptions">Helpful exceptions</h2>
<div class="highlight">
<pre>
ReceivedCallsException : Expected to receive a call matching:
Add(1, 2)
Actually received no matching calls.
Received 2 non-matching calls (non-matching arguments indicated with '*' characters):
Add(*4*, *7*)
Add(1, *5*)</pre>
</div>
</div>
<div class="feature">
<a id="dont_sweat_the_small_stuff"></a>
<h2 id="dont-sweat-the-small-stuff">Don’t sweat the small stuff</h2>
<p>Mock, stub, fake, spy, test double? Strict or loose? Nah, just substitute for the type you need!</p>
<p>NSubstitute is designed for Arrange-Act-Assert (AAA) testing, so you just need to arrange how it should work, then assert it received the calls you expected once you're done. Because you've got more important code to write than whether you need a mock or a stub.</p>
</div>
</div>
<div id="downloads" class="sidebar download">
<ul>
<li class="nuget">
<a href="https://nuget.org/List/Packages/NSubstitute">Install via NuGet:</a> <code>Install-Package NSubstitute</code>
</li>
<li class="nuget"><a href="/help/nsubstitute-analysers/">Optional analysers for C#:</a>
<code>Install-Package NSubstitute.<wbr />Analyzers.<wbr />CSharp</code>
</li>
<li class="nuget"><a href="/help/nsubstitute-analysers/">Optional analysers for VB:</a>
<code>Install-Package NSubstitute.<wbr />Analyzers.<wbr />VisualBasic</code>
</li>
<li class="github">
<a href="https://github.com/nsubstitute/nsubstitute">Source</a>
</li>
</ul>
</div>
<div class="sidebar">
<div id="why-use-it">
<a id="another_library"></a>
<h3 id="another-library">Another library?</h3>
<p>There are already some great mocking libraries around for .NET, so why create another? We found that for all their great features, none of the existing libraries had the succinct syntax we were craving — the code required to configure test doubles quickly obscured the intention behind our tests.</p>
<p>We've attempted to make the most frequently required operations obvious and easy to use, keeping less usual scenarios discoverable and accessible, and all the while maintaining as much natural language as possible.</p>
<p>Perfect for those new to testing, and for others who would just like to to get their tests written with less noise and fewer lambdas.</p>
</div>
</div>
</div>
<div id="footer">
NSubstitute is open source software, licensed under the <a href="https://www.opensource.org/licenses/bsd-license.php">BSD License</a>.<br />
The NSubstitute project is possible <a href="https://github.com/nsubstitute/NSubstitute/blob/master/acknowledgements.md">thanks to a number of other software projects</a>. We acknowledge their awesomeness.<br />
NSubstitute logo donated by <a href="https://troyhunt.com">Troy Hunt</a>.
</div>
</body>
</html>