Skip to content

Commit

Permalink
Enable nullables for Framework (#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Nov 3, 2022
1 parent 9bc985c commit a03fb56
Show file tree
Hide file tree
Showing 37 changed files with 539 additions and 603 deletions.
150 changes: 77 additions & 73 deletions src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs

Large diffs are not rendered by default.

40 changes: 21 additions & 19 deletions src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed partial class Assert
/// Thrown if <paramref name="expected"/> does not refer to the same object
/// as <paramref name="actual"/>.
/// </exception>
public static void AreSame(object expected, object actual)
public static void AreSame(object? expected, object? actual)
{
AreSame(expected, actual, string.Empty, null);
}
Expand All @@ -51,7 +51,7 @@ public static void AreSame(object expected, object actual)
/// Thrown if <paramref name="expected"/> does not refer to the same object
/// as <paramref name="actual"/>.
/// </exception>
public static void AreSame(object expected, object actual, string message)
public static void AreSame(object? expected, object? actual, string? message)
{
AreSame(expected, actual, message, null);
}
Expand All @@ -78,26 +78,28 @@ public static void AreSame(object expected, object actual, string message)
/// Thrown if <paramref name="expected"/> does not refer to the same object
/// as <paramref name="actual"/>.
/// </exception>
public static void AreSame(object expected, object actual, string message, params object[] parameters)
public static void AreSame(object? expected, object? actual, string? message, params object?[]? parameters)
{
if (!ReferenceEquals(expected, actual))
if (ReferenceEquals(expected, actual))
{
string userMessage = BuildUserMessage(message, parameters);
string finalMessage = userMessage;
return;
}

string userMessage = BuildUserMessage(message, parameters);
string finalMessage = userMessage;

if (expected is ValueType valExpected)
if (expected is ValueType)
{
if (actual is ValueType)
{
if (actual is ValueType valActual)
{
finalMessage = string.Format(
CultureInfo.CurrentCulture,
FrameworkMessages.AreSameGivenValues,
userMessage);
}
finalMessage = string.Format(
CultureInfo.CurrentCulture,
FrameworkMessages.AreSameGivenValues,
userMessage);
}

ThrowAssertFailed("Assert.AreSame", finalMessage);
}

ThrowAssertFailed("Assert.AreSame", finalMessage);
}

/// <summary>
Expand All @@ -115,7 +117,7 @@ public static void AreSame(object expected, object actual, string message, param
/// Thrown if <paramref name="notExpected"/> refers to the same object
/// as <paramref name="actual"/>.
/// </exception>
public static void AreNotSame(object notExpected, object actual)
public static void AreNotSame(object? notExpected, object? actual)
{
AreNotSame(notExpected, actual, string.Empty, null);
}
Expand All @@ -140,7 +142,7 @@ public static void AreNotSame(object notExpected, object actual)
/// Thrown if <paramref name="notExpected"/> refers to the same object
/// as <paramref name="actual"/>.
/// </exception>
public static void AreNotSame(object notExpected, object actual, string message)
public static void AreNotSame(object? notExpected, object? actual, string? message)
{
AreNotSame(notExpected, actual, message, null);
}
Expand Down Expand Up @@ -168,7 +170,7 @@ public static void AreNotSame(object notExpected, object actual, string message)
/// Thrown if <paramref name="notExpected"/> refers to the same object
/// as <paramref name="actual"/>.
/// </exception>
public static void AreNotSame(object notExpected, object actual, string message, params object[] parameters)
public static void AreNotSame(object? notExpected, object? actual, string? message, params object?[]? parameters)
{
if (ReferenceEquals(notExpected, actual))
{
Expand Down
4 changes: 2 additions & 2 deletions src/TestFramework/TestFramework/Assertions/Assert.Fail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void Fail()
/// Always thrown.
/// </exception>
[DoesNotReturn]
public static void Fail(string message)
public static void Fail(string? message)
{
Fail(message, null);
}
Expand All @@ -54,7 +54,7 @@ public static void Fail(string message)
/// Always thrown.
/// </exception>
[DoesNotReturn]
public static void Fail(string message, params object[] parameters)
public static void Fail(string? message, params object?[]? parameters)
{
ThrowAssertFailed("Assert.Fail", BuildUserMessage(message, parameters));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void Inconclusive()
/// <exception cref="AssertInconclusiveException">
/// Always thrown.
/// </exception>
public static void Inconclusive(string message)
public static void Inconclusive(string? message)
{
Inconclusive(message, null);
}
Expand All @@ -51,7 +51,7 @@ public static void Inconclusive(string message)
/// <exception cref="AssertInconclusiveException">
/// Always thrown.
/// </exception>
public static void Inconclusive(string message, params object[] parameters)
public static void Inconclusive(string? message, params object?[]? parameters)
{
string userMessage = BuildUserMessage(message, parameters);
throw new AssertInconclusiveException(string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AssertionFailed, "Assert.Inconclusive", userMessage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed partial class Assert
/// <paramref name="expectedType"/> is not in the inheritance hierarchy
/// of <paramref name="value"/>.
/// </exception>
public static void IsInstanceOfType(object value, Type expectedType)
public static void IsInstanceOfType(object? value, Type? expectedType)
{
IsInstanceOfType(value, expectedType, string.Empty, null);
}
Expand All @@ -41,7 +41,7 @@ public static void IsInstanceOfType(object value, Type expectedType)
/// inheritance hierarchy of the object.
/// </summary>
/// <typeparam name="T">The expected type of <paramref name="value"/>.</typeparam>
public static void IsInstanceOfType<T>(object value)
public static void IsInstanceOfType<T>(object? value)
{
IsInstanceOfType(value, typeof(T), string.Empty, null);
}
Expand All @@ -67,7 +67,7 @@ public static void IsInstanceOfType<T>(object value)
/// <paramref name="expectedType"/> is not in the inheritance hierarchy
/// of <paramref name="value"/>.
/// </exception>
public static void IsInstanceOfType(object value, Type expectedType, string message)
public static void IsInstanceOfType(object? value, Type? expectedType, string? message)
{
IsInstanceOfType(value, expectedType, message, null);
}
Expand All @@ -78,7 +78,7 @@ public static void IsInstanceOfType(object value, Type expectedType, string mess
/// inheritance hierarchy of the object.
/// </summary>
/// <typeparam name="T">The expected type of <paramref name="value"/>.</typeparam>
public static void IsInstanceOfType<T>(object value, string message)
public static void IsInstanceOfType<T>(object? value, string? message)
{
IsInstanceOfType(value, typeof(T), message, null);
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void IsInstanceOfType<T>(object value, string message)
/// <paramref name="expectedType"/> is not in the inheritance hierarchy
/// of <paramref name="value"/>.
/// </exception>
public static void IsInstanceOfType(object value, Type expectedType, string message, params object[] parameters)
public static void IsInstanceOfType(object? value, Type? expectedType, string? message, params object?[]? parameters)
{
if (expectedType == null || value == null)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ public static void IsInstanceOfType(object value, Type expectedType, string mess
/// inheritance hierarchy of the object.
/// </summary>
/// <typeparam name="T">The expected type of <paramref name="value"/>.</typeparam>
public static void IsInstanceOfType<T>(object value, string message, params object[] parameters)
public static void IsInstanceOfType<T>(object? value, string? message, params object?[]? parameters)
{
IsInstanceOfType(value, typeof(T), message, parameters);
}
Expand All @@ -156,7 +156,7 @@ public static void IsInstanceOfType<T>(object value, string message, params obje
/// <paramref name="wrongType"/> is in the inheritance hierarchy
/// of <paramref name="value"/>.
/// </exception>
public static void IsNotInstanceOfType(object value, Type wrongType)
public static void IsNotInstanceOfType(object? value, Type? wrongType)
{
IsNotInstanceOfType(value, wrongType, string.Empty, null);
}
Expand All @@ -167,7 +167,7 @@ public static void IsNotInstanceOfType(object value, Type wrongType)
/// inheritance hierarchy of the object.
/// </summary>
/// <typeparam name="T">The type that <paramref name="value"/> should not be.</typeparam>
public static void IsNotInstanceOfType<T>(object value)
public static void IsNotInstanceOfType<T>(object? value)
{
IsNotInstanceOfType(value, typeof(T), string.Empty, null);
}
Expand All @@ -193,7 +193,7 @@ public static void IsNotInstanceOfType<T>(object value)
/// <paramref name="wrongType"/> is in the inheritance hierarchy
/// of <paramref name="value"/>.
/// </exception>
public static void IsNotInstanceOfType(object value, Type wrongType, string message)
public static void IsNotInstanceOfType(object? value, Type? wrongType, string? message)
{
IsNotInstanceOfType(value, wrongType, message, null);
}
Expand All @@ -204,7 +204,7 @@ public static void IsNotInstanceOfType(object value, Type wrongType, string mess
/// inheritance hierarchy of the object.
/// </summary>
/// <typeparam name="T">The type that <paramref name="value"/> should not be.</typeparam>
public static void IsNotInstanceOfType<T>(object value, string message)
public static void IsNotInstanceOfType<T>(object? value, string? message)
{
IsNotInstanceOfType(value, typeof(T), message, null);
}
Expand Down Expand Up @@ -233,7 +233,7 @@ public static void IsNotInstanceOfType<T>(object value, string message)
/// <paramref name="wrongType"/> is in the inheritance hierarchy
/// of <paramref name="value"/>.
/// </exception>
public static void IsNotInstanceOfType(object value, Type wrongType, string message, params object[] parameters)
public static void IsNotInstanceOfType(object? value, Type? wrongType, string? message, params object?[]? parameters)
{
if (wrongType == null)
{
Expand Down Expand Up @@ -267,7 +267,7 @@ public static void IsNotInstanceOfType(object value, Type wrongType, string mess
/// inheritance hierarchy of the object.
/// </summary>
/// <typeparam name="T">The type that <paramref name="value"/> should not be.</typeparam>
public static void IsNotInstanceOfType<T>(object value, string message, params object[] parameters)
public static void IsNotInstanceOfType<T>(object? value, string? message, params object?[]? parameters)
{
IsNotInstanceOfType(value, typeof(T), message, parameters);
}
Expand Down
12 changes: 6 additions & 6 deletions src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed partial class Assert
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="value"/> is not null.
/// </exception>
public static void IsNull(object value)
public static void IsNull(object? value)
{
IsNull(value, string.Empty, null);
}
Expand All @@ -41,7 +41,7 @@ public static void IsNull(object value)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="value"/> is not null.
/// </exception>
public static void IsNull(object value, string message)
public static void IsNull(object? value, string? message)
{
IsNull(value, message, null);
}
Expand All @@ -63,7 +63,7 @@ public static void IsNull(object value, string message)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="value"/> is not null.
/// </exception>
public static void IsNull(object value, string message, params object[] parameters)
public static void IsNull(object? value, string? message, params object?[]? parameters)
{
if (value != null)
{
Expand All @@ -81,7 +81,7 @@ public static void IsNull(object value, string message, params object[] paramete
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="value"/> is null.
/// </exception>
public static void IsNotNull([NotNull] object value)
public static void IsNotNull(object? value)
{
IsNotNull(value, string.Empty, null);
}
Expand All @@ -100,7 +100,7 @@ public static void IsNotNull([NotNull] object value)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="value"/> is null.
/// </exception>
public static void IsNotNull([NotNull] object value, string message)
public static void IsNotNull(object? value, string? message)
{
IsNotNull(value, message, null);
}
Expand All @@ -122,7 +122,7 @@ public static void IsNotNull([NotNull] object value, string message)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="value"/> is null.
/// </exception>
public static void IsNotNull([NotNull] object value, string message, params object[] parameters)
public static void IsNotNull(object? value, string? message, params object?[]? parameters)
{
if (value == null)
{
Expand Down
16 changes: 8 additions & 8 deletions src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue([DoesNotReturnIf(false)] bool condition, string message)
public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? message)
{
IsTrue(condition, message, null);
}
Expand All @@ -75,7 +75,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, string messag
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string message)
public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? message)
{
IsTrue(condition, message, null);
}
Expand All @@ -97,7 +97,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string messa
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue([DoesNotReturnIf(false)] bool condition, string message, params object[] parameters)
public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? message, params object?[]? parameters)
{
if (!condition)
{
Expand All @@ -122,7 +122,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, string messag
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string message, params object[] parameters)
public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? message, params object?[]? parameters)
{
if (condition is false or null)
{
Expand Down Expand Up @@ -174,7 +174,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse([DoesNotReturnIf(true)] bool condition, string message)
public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? message)
{
IsFalse(condition, message, null);
}
Expand All @@ -193,7 +193,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, string messag
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string message)
public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? message)
{
IsFalse(condition, message, null);
}
Expand All @@ -215,7 +215,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string messa
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse([DoesNotReturnIf(true)] bool condition, string message, params object[] parameters)
public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? message, params object?[]? parameters)
{
if (condition)
{
Expand All @@ -240,7 +240,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, string messag
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string message, params object[] parameters)
public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? message, params object?[]? parameters)
{
if (condition is true or null)
{
Expand Down

0 comments on commit a03fb56

Please sign in to comment.