Skip to content

Commit ca7744e

Browse files
committed
Merge pull request #1070 from nunit/updateEqualTo
Updated EqualTo constraint fb945da
1 parent b1c2ad5 commit ca7744e

File tree

3 files changed

+734
-730
lines changed

3 files changed

+734
-730
lines changed

articles/nunit/writing-tests/constraints/EqualConstraint.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ <h2 id="syntax">Syntax</h2>
9696
Is.Zero // Equivalent to Is.EqualTo(0)
9797
</code></pre>
9898
<h2 id="modifiers">Modifiers</h2>
99-
<pre><code class="lang-csharp">...IgnoreCase
99+
<pre><code class="lang-csharp">...AsCollection
100+
...IgnoreCase
100101
...IgnoreWhiteSpace // From version 4.2
101-
...AsCollection
102102
...NoClip
103103
...WithSameOffset
104104
...Within(object tolerance)
@@ -110,8 +110,7 @@ <h2 id="modifiers">Modifiers</h2>
110110
.Seconds
111111
.Milliseconds
112112
.Ticks
113-
...IgnoreCase
114-
...IgnoreWhiteSpace
113+
115114
...Using(IEqualityComparer comparer)
116115
...Using(IComparer comparer)
117116
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
@@ -159,12 +158,16 @@ <h2 id="comparing-numerics">Comparing Numerics</h2>
159158
<pre><code class="lang-csharp" name="EqualConstraintStrings">[Test]
160159
public void EqualConstraint_Strings()
161160
{
162-
Assert.That(&quot;Hello!&quot;, Is.Not.EqualTo(&quot;HELLO!&quot;));
163-
Assert.That(&quot;Hello!&quot;, Is.EqualTo(&quot;HELLO!&quot;).IgnoreCase);
161+
string hello = &quot;Hello!&quot;;
162+
Assert.That(hello, Is.Not.EqualTo(&quot;HELLO!&quot;));
163+
Assert.That(hello, Is.EqualTo(&quot;HELLO!&quot;).IgnoreCase); // Ignores case in both actual and expected before comparing
164164

165165
string[] expected = [&quot;Hello&quot;, &quot;World&quot;];
166166
string[] actual = [&quot;HELLO&quot;, &quot;world&quot;];
167167
Assert.That(actual, Is.EqualTo(expected).IgnoreCase);
168+
string actualiws = &quot;Hello my world is \r\n on fire!&quot;;
169+
string expectediws = &quot;Hellomy world \r\n is on fire!&quot;;
170+
Assert.That(actualiws, Is.EqualTo(expectediws).IgnoreWhiteSpace); // Ignores white space in both actual and expected before comparing
168171
}
169172
</code></pre>
170173
<p>Sometimes we need to compare strings irrespective of white space characters, e.g.: when comparing Json strings.
@@ -200,6 +203,7 @@ <h2 id="comparing-numerics">Comparing Numerics</h2>
200203
------------------------------------------------------^
201204
</code></pre>
202205
<p>The <code>IgnoreWhiteSpace</code> can also be specified when comparing collections of strings.</p>
206+
<p>The characters ignored are the same as for the C# <code>Char.IsWhiteSpace</code>.</p>
203207
<h2 id="comparing-datetimes-and-timespans">Comparing DateTimes and TimeSpans</h2>
204208
<p><strong>DateTimes</strong> and <strong>TimeSpans</strong> may be compared either with or without a tolerance. A tolerance is specified using
205209
<strong>Within</strong> with either a <strong>TimeSpan</strong> as an argument or with a numeric value followed by a one of the time conversion
@@ -213,7 +217,7 @@ <h2 id="comparing-datetimes-and-timespans">Comparing DateTimes and TimeSpans</h2
213217
Assert.That(later, Is.EqualTo(now).Within(TimeSpan.FromHours(3.0));
214218
Assert.That(later, Is.EqualTo(now).Within(3).Hours);
215219
</code></pre>
216-
<h2 id="comparing-arrays-collections-and-ienumerables">Comparing Arrays, Collections and IEnumerables</h2>
220+
<h2 id="comparing-arrays-collections-and-ienumerables-with-ascollection">Comparing Arrays, Collections and IEnumerables with AsCollection</h2>
217221
<p>Since version 2.2, NUnit has been able to compare two single-dimensioned arrays. Beginning with version 2.4,
218222
multi-dimensioned arrays, nested arrays (arrays of arrays) and collections may be compared. With version 2.5, any
219223
IEnumerable is supported. Two arrays, collections or IEnumerables are considered equal if they have the same dimensions

0 commit comments

Comments
 (0)