Skip to content

Commit 551ac18

Browse files
authored
Add CallerArgumentExpression to IsNull/IsNotNull (#254)
***NO_CI***
1 parent 5465639 commit 551ac18

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

source/TestFramework/Assert.cs

+9-11
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ public static void Equal(
170170
/// <param name="expected">The first value to compare. This is the value the tests expects.</param>
171171
/// <param name="actual">The second value to compare. This is the value produced by the code under test.</param>
172172
/// <param name="message"> The message to include in the exception when <paramref name="actual"/> is not equal to <paramref name="expected"/>. The message is shown in test results.</param>
173-
/// <param name="message"> The message to include in the exception when <paramref name="actual"/> is not equal to <paramref name="expected"/>. The message is shown in test results.</param>
174173
/// <exception cref="AssertFailedException">Thrown if <paramref name="expected"/> is not equal to <paramref name="actual"/>.</exception>
175174
public static void AreEqual(
176175
int expected,
@@ -192,7 +191,6 @@ public static void AreEqual(
192191
/// <param name="expected">The first value to compare. This is the value the tests expects.</param>
193192
/// <param name="actual">The second value to compare. This is the value produced by the code under test.</param>
194193
/// <param name="message"> The message to include in the exception when <paramref name="actual"/> is not equal to <paramref name="expected"/>. The message is shown in test results.</param>
195-
/// <param name="message"> The message to include in the exception when <paramref name="actual"/> is not equal to <paramref name="expected"/>. The message is shown in test results.</param>
196194
/// <exception cref="AssertFailedException">Thrown if <paramref name="expected"/> is not equal to <paramref name="actual"/>.</exception>
197195
[Obsolete("This method is deprecated and will be removed in a future version. Use the new method AreEqual.")]
198196
public static void Equal(
@@ -1600,7 +1598,7 @@ public static void NotSame(
16001598
/// <param name="value">The object the test expects to be null.</param>
16011599
/// <param name="message">The message to include in the exception when value is not null. The message is shown in test results.</param>
16021600
/// <exception cref="AssertFailedException">Thrown if value is not null.</exception>
1603-
public static void IsNull(object value, string message = "")
1601+
public static void IsNull(object value, [CallerArgumentExpression(nameof(value))] string message = "")
16041602
{
16051603
if (value is not null)
16061604
{
@@ -1623,7 +1621,7 @@ public static void IsNull(object value, string message = "")
16231621
/// <param name="value">The object the test expects not to be null.</param>
16241622
/// <param name="message">The message to include in the exception when value is null. The message is shown in test results.</param>
16251623
/// <exception cref="AssertFailedException">Thrown if value is null.</exception>
1626-
public static void IsNotNull([NotNull] object value, string message = "")
1624+
public static void IsNotNull([NotNull] object value, [CallerArgumentExpression(nameof(value))] string message = "")
16271625
{
16281626
if (value is null)
16291627
{
@@ -1636,19 +1634,19 @@ public static void IsNotNull([NotNull] object value, string message = "")
16361634
/// </summary>
16371635
/// <param name="value">The object the test expects not to be null.</param>
16381636
/// <param name="message">The message to include in the exception when value is null. The message is shown in test results.</param>
1639-
/// <exception cref="AssertFailedException">Thrown if value is null./exception>
1637+
/// <exception cref="AssertFailedException">Thrown if value is null.</exception>
16401638
[Obsolete("This method is deprecated and will be removed in a future version. Use the new method IsNotNull.")]
16411639
public static void NotNull(object obj, string message = "") => IsNotNull(obj, message);
16421640

16431641
/// <summary>
16441642
/// Tests whether the code specified by delegate action throws exact given exception
16451643
/// of type <paramref name="exceptionType"/> (and not of derived type) and throws <see cref="AssertFailedException"/> if code
1646-
/// does not throws exception or throws exception of type other than <paramref name="exceptionType"/>.
1644+
/// does not throw exception or throws exception of type other than <paramref name="exceptionType"/>.
16471645
/// </summary>
16481646
/// <param name="exceptionType">Type of exception expected to be thrown.</param>
16491647
/// <param name="action">Delegate to code to be tested and which is expected to throw exception.</param>
1650-
/// <param name="message">The message to include in the exception when action does not throws exception of type <paramref name="exceptionType"/>.</param>
1651-
/// <exception cref="AssertFailedException">Thrown if action does not throws exception of type <paramref name="exceptionType"/>.</exception>
1648+
/// <param name="message">The message to include in the exception when action does not throw exception of type <paramref name="exceptionType"/>.</param>
1649+
/// <exception cref="AssertFailedException">Thrown if action does not throw exception of type <paramref name="exceptionType"/>.</exception>
16521650
/// <exception cref="ArgumentNullException">Thrown if <paramref name="action"/> is <see langword="null"/>.</exception>
16531651
public static void ThrowsException(
16541652
Type exceptionType,
@@ -1688,12 +1686,12 @@ public static void ThrowsException(
16881686
/// <summary>
16891687
/// Tests whether the code specified by delegate action throws exact given exception
16901688
/// of type <paramref name="exceptionType"/> (and not of derived type) and throws <see cref="AssertFailedException"/> if code
1691-
/// does not throws exception or throws exception of type other than <paramref name="exceptionType"/>.
1689+
/// does not throw exception or throws exception of type other than <paramref name="exceptionType"/>.
16921690
/// </summary>
16931691
/// <param name="exceptionType">Type of exception expected to be thrown.</param>
16941692
/// <param name="action">Delegate to code to be tested and which is expected to throw exception.</param>
1695-
/// <param name="message">The message to include in the exception when action does not throws exception of type <paramref name="exceptionType"/>.</param>
1696-
/// <exception cref="AssertFailedException">Thrown if action does not throws exception of type <paramref name="exceptionType"/>.</exception>
1693+
/// <param name="message">The message to include in the exception when action does not throw exception of type <paramref name="exceptionType"/>.</param>
1694+
/// <exception cref="AssertFailedException">Thrown if action does not throw exception of type <paramref name="exceptionType"/>.</exception>
16971695
/// <exception cref="ArgumentNullException">Thrown if <paramref name="action"/> is <see langword="null"/>.</exception>
16981696
[Obsolete("This method is deprecated and will be removed in a future version. Use the new method ThrowsException.")]
16991697
public static void Throws(

0 commit comments

Comments
 (0)