DoesNotContainValue(expected,
(actual, _, _) =>
{
- ArgumentNullException.ThrowIfNull(actual);
+ Verify.ArgNotNull(actual);
return !actual.Values.Cast().Contains(expected, equalityComparer);
},
(_, _, _) => $"The value \"{expected}\" was found in the dictionary",
diff --git a/TUnit.Assertions/Assertions/Generics/Conditions/AssignableToExpectedValueAssertCondition.cs b/TUnit.Assertions/Assertions/Generics/Conditions/AssignableToExpectedValueAssertCondition.cs
index 7419ab83ee..f344530839 100644
--- a/TUnit.Assertions/Assertions/Generics/Conditions/AssignableToExpectedValueAssertCondition.cs
+++ b/TUnit.Assertions/Assertions/Generics/Conditions/AssignableToExpectedValueAssertCondition.cs
@@ -13,6 +13,6 @@ protected override Task GetResult(TActual? actualValue, Excepti
.FailIf(() => actualValue is null,
() => "actual is null")
.OrFailIf(
- () => !actualValue!.GetType().IsAssignableTo(expectedType),
+ () => !expectedType.IsAssignableFrom(actualValue!.GetType()),
() => $"it is {ActualValue?.GetType().Name ?? "null"}");
}
\ No newline at end of file
diff --git a/TUnit.Assertions/Assertions/Generics/Conditions/EqualsExpectedValueAssertCondition.cs b/TUnit.Assertions/Assertions/Generics/Conditions/EqualsExpectedValueAssertCondition.cs
index bcd19f8e5f..443896c93e 100644
--- a/TUnit.Assertions/Assertions/Generics/Conditions/EqualsExpectedValueAssertCondition.cs
+++ b/TUnit.Assertions/Assertions/Generics/Conditions/EqualsExpectedValueAssertCondition.cs
@@ -1,4 +1,7 @@
-using TUnit.Assertions.AssertConditions;
+#if !NET
+#pragma warning disable CS8604 // Possible null reference argument.
+#endif
+using TUnit.Assertions.AssertConditions;
namespace TUnit.Assertions.Assertions.Generics.Conditions;
diff --git a/TUnit.Assertions/Assertions/Generics/Conditions/EquivalentToExpectedValueAssertCondition.cs b/TUnit.Assertions/Assertions/Generics/Conditions/EquivalentToExpectedValueAssertCondition.cs
index 2a9c08bca7..2aa849da33 100644
--- a/TUnit.Assertions/Assertions/Generics/Conditions/EquivalentToExpectedValueAssertCondition.cs
+++ b/TUnit.Assertions/Assertions/Generics/Conditions/EquivalentToExpectedValueAssertCondition.cs
@@ -40,7 +40,7 @@ protected override AssertionResult GetResult(TActual? actualValue, TExpected? ex
{
MembersToIgnore = [.._ignoredMembers]
})),
- () => $"it is {string.Join(',', actualEnumerable)}");
+ () => $"it is {string.Join(",", actualEnumerable)}");
}
bool? isEqual = null;
@@ -78,7 +78,7 @@ protected override AssertionResult GetResult(TActual? actualValue, TExpected? ex
}
return FailWithMessage($"""
- {firstFailure.Type} {string.Join('.', firstFailure.NestedMemberNames)} did not match
+ {firstFailure.Type} {string.Join(".", firstFailure.NestedMemberNames)} did not match
Expected: {Formatter.Format(firstFailure.Expected)}
Received: {Formatter.Format(firstFailure.Actual)}
""");
diff --git a/TUnit.Assertions/Assertions/Generics/Conditions/NotAssignableToExpectedValueAssertCondition.cs b/TUnit.Assertions/Assertions/Generics/Conditions/NotAssignableToExpectedValueAssertCondition.cs
index 3a1ed86874..dfb1cb59fd 100644
--- a/TUnit.Assertions/Assertions/Generics/Conditions/NotAssignableToExpectedValueAssertCondition.cs
+++ b/TUnit.Assertions/Assertions/Generics/Conditions/NotAssignableToExpectedValueAssertCondition.cs
@@ -13,6 +13,6 @@ protected override Task GetResult(TActual? actualValue, Excepti
.FailIf(() => actualValue is null,
() => "actual is null")
.OrFailIf(
- () => actualValue!.GetType().IsAssignableTo(expectedType),
+ () => expectedType.IsAssignableFrom(actualValue!.GetType()),
() => $"it is {ActualValue?.GetType().Name ?? "null"}");
}
\ No newline at end of file
diff --git a/TUnit.Assertions/Assertions/Numbers/NumberIsExtensions.cs b/TUnit.Assertions/Assertions/Numbers/NumberIsExtensions.cs
index d2118401e4..2f677952ad 100644
--- a/TUnit.Assertions/Assertions/Numbers/NumberIsExtensions.cs
+++ b/TUnit.Assertions/Assertions/Numbers/NumberIsExtensions.cs
@@ -1,5 +1,7 @@
#nullable disable
+#if NET
+
using System.Numerics;
using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
@@ -134,4 +136,6 @@ public static InvokableValueAssertionBuilder IsPositive(
$"to be positive")
, []);
}
-}
\ No newline at end of file
+}
+
+#endif
diff --git a/TUnit.Assertions/Assertions/Numbers/NumberIsNotExtensions.cs b/TUnit.Assertions/Assertions/Numbers/NumberIsNotExtensions.cs
index 5280fffb50..ba24dfeb4c 100644
--- a/TUnit.Assertions/Assertions/Numbers/NumberIsNotExtensions.cs
+++ b/TUnit.Assertions/Assertions/Numbers/NumberIsNotExtensions.cs
@@ -1,5 +1,7 @@
#nullable disable
+#if NET
+
using System.Numerics;
using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
@@ -201,4 +203,6 @@ public static InvokableValueAssertionBuilder IsNotPositive(thi
$"to not be positive")
, []);
}
-}
\ No newline at end of file
+}
+
+#endif
diff --git a/TUnit.Assertions/Assertions/Strings/DoesExtensions_String.cs b/TUnit.Assertions/Assertions/Strings/DoesExtensions_String.cs
index b6eebc1a3b..1f071a1b8b 100644
--- a/TUnit.Assertions/Assertions/Strings/DoesExtensions_String.cs
+++ b/TUnit.Assertions/Assertions/Strings/DoesExtensions_String.cs
@@ -59,7 +59,7 @@ public static InvokableValueAssertionBuilder EndsWith(this IValueSource<
return valueSource.RegisterAssertion(new FuncValueAssertCondition(expected,
(actual, _, _) =>
{
- ArgumentNullException.ThrowIfNull(actual);
+ Verify.ArgNotNull(actual);
return actual.EndsWith(expected, stringComparison);
},
(actual, _, _) => $"\"{actual}\" does not end with \"{expected}\"",
@@ -77,7 +77,7 @@ public static InvokableValueAssertionBuilder Matches(this IValueSource(regex,
(actual, _, _) =>
{
- ArgumentNullException.ThrowIfNull(actual);
+ Verify.ArgNotNull(actual);
return regex.IsMatch(actual);
},
(actual, _, _) => $"The regex \"{regex}\" does not match with \"{actual}\"",
diff --git a/TUnit.Assertions/Assertions/Strings/DoesNotExtensions_String.cs b/TUnit.Assertions/Assertions/Strings/DoesNotExtensions_String.cs
index 74e95e7ddb..28ba392f99 100644
--- a/TUnit.Assertions/Assertions/Strings/DoesNotExtensions_String.cs
+++ b/TUnit.Assertions/Assertions/Strings/DoesNotExtensions_String.cs
@@ -31,7 +31,7 @@ public static InvokableValueAssertionBuilder DoesNotStartWith(this IValu
return valueSource.RegisterAssertion(new FuncValueAssertCondition(expected,
(actual, _, _) =>
{
- ArgumentNullException.ThrowIfNull(actual);
+ Verify.ArgNotNull(actual);
return !actual.StartsWith(expected, stringComparison);
},
(actual, _, _) => $"\"{actual}\" does start with \"{expected}\"",
@@ -50,7 +50,7 @@ public static InvokableValueAssertionBuilder DoesNotEndWith(this IValueS
return valueSource.RegisterAssertion(new FuncValueAssertCondition(expected,
(actual, _, _) =>
{
- ArgumentNullException.ThrowIfNull(actual);
+ Verify.ArgNotNull(actual);
return !actual.EndsWith(expected, stringComparison);
},
(actual, _, _) => $"\"{actual}\" does end with \"{expected}\"",
diff --git a/TUnit.Assertions/Assertions/Throws/ThrowsOfTypeAssertCondition.cs b/TUnit.Assertions/Assertions/Throws/ThrowsOfTypeAssertCondition.cs
index 011a20722e..b5d99ceb3c 100644
--- a/TUnit.Assertions/Assertions/Throws/ThrowsOfTypeAssertCondition.cs
+++ b/TUnit.Assertions/Assertions/Throws/ThrowsOfTypeAssertCondition.cs
@@ -13,7 +13,7 @@ protected override Task GetResult(TActual? actualValue, Excepti
() => exception is null,
() => "none was thrown")
.OrFailIf(
- () => !exception!.GetType().IsAssignableTo(typeof(TExpectedException)),
+ () => !typeof(TExpectedException).IsAssignableFrom(exception!.GetType()),
() => $"{exception?.GetType().Name.PrependAOrAn()} was thrown"
);
}
\ No newline at end of file
diff --git a/TUnit.Assertions/Compare.cs b/TUnit.Assertions/Compare.cs
index c482c5fecb..28e2e84483 100644
--- a/TUnit.Assertions/Compare.cs
+++ b/TUnit.Assertions/Compare.cs
@@ -83,7 +83,7 @@ private static IEnumerable CheckEquivalent<
{
string?[] readOnlySpan = [..memberNames, $"[{i}]"];
- if (options.MembersToIgnore.Contains(string.Join('.', readOnlySpan)))
+ if (options.MembersToIgnore.Contains(string.Join(".", readOnlySpan)))
{
continue;
}
@@ -106,7 +106,7 @@ private static IEnumerable CheckEquivalent<
{
string?[] readOnlySpan = [..memberNames, fieldName];
- if (options.MembersToIgnore.Contains(string.Join('.', readOnlySpan)))
+ if (options.MembersToIgnore.Contains(string.Join(".", readOnlySpan)))
{
continue;
}
@@ -147,7 +147,7 @@ private static IEnumerable CheckEquivalent<
{
string?[] readOnlySpan = [..memberNames, propertyName];
- if (options.MembersToIgnore.Contains(string.Join('.', readOnlySpan)))
+ if (options.MembersToIgnore.Contains(string.Join(".", readOnlySpan)))
{
continue;
}
diff --git a/TUnit.Assertions/Equality/EquivalentToEqualityComparer.cs b/TUnit.Assertions/Equality/EquivalentToEqualityComparer.cs
index 44f9808a7a..9175d34af5 100644
--- a/TUnit.Assertions/Equality/EquivalentToEqualityComparer.cs
+++ b/TUnit.Assertions/Equality/EquivalentToEqualityComparer.cs
@@ -1,4 +1,8 @@
-using System.Diagnostics.CodeAnalysis;
+#if !NET
+#pragma warning disable CS8767 // Nullability of type parameters in type of collection doesn't match implicitly implemented member (possibly because of nullability attributes).
+#endif
+
+using System.Diagnostics.CodeAnalysis;
namespace TUnit.Assertions.Equality;
diff --git a/TUnit.Assertions/ExceptionsHelper.cs b/TUnit.Assertions/ExceptionsHelper.cs
index 0e31aefd39..b3def8b13a 100644
--- a/TUnit.Assertions/ExceptionsHelper.cs
+++ b/TUnit.Assertions/ExceptionsHelper.cs
@@ -10,7 +10,7 @@ public static void ThrowIfAny(IReadOnlyList exceptions)
{
if (exceptions.Count == 1)
{
- ExceptionDispatchInfo.Throw(exceptions[0]);
+ ExceptionDispatchInfo.Capture(exceptions[0]).Throw();
}
if (exceptions.Count > 1)
diff --git a/TUnit.Assertions/Extensions/NumberExtensions.cs b/TUnit.Assertions/Extensions/NumberExtensions.cs
index cefbb71ba9..79514260a7 100644
--- a/TUnit.Assertions/Extensions/NumberExtensions.cs
+++ b/TUnit.Assertions/Extensions/NumberExtensions.cs
@@ -1,4 +1,6 @@
-using System.Numerics;
+#if NET
+
+using System.Numerics;
namespace TUnit.Assertions.Extensions;
@@ -9,4 +11,6 @@ public static bool IsBetween(this INumber number, INumber= 0 && number.CompareTo(max) <= 0;
}
-}
\ No newline at end of file
+}
+
+#endif
diff --git a/TUnit.Assertions/Extensions/StringExtensions.cs b/TUnit.Assertions/Extensions/StringExtensions.cs
index 10034a212b..139a7c033e 100644
--- a/TUnit.Assertions/Extensions/StringExtensions.cs
+++ b/TUnit.Assertions/Extensions/StringExtensions.cs
@@ -14,7 +14,9 @@ public static string GetStringOr(this string? value, string defaultValue)
public static string ReplaceNewLines(this string value)
{
- return value.ReplaceLineEndings(" ");
+ return value.Replace("\r\n", " ")
+ .Replace("\n", " ")
+ .Replace("\r", " ");
}
public static string ShowNewLines(this string value)
diff --git a/TUnit.Assertions/Helpers/Formatter.cs b/TUnit.Assertions/Helpers/Formatter.cs
index df0445a0c2..399c21750a 100644
--- a/TUnit.Assertions/Helpers/Formatter.cs
+++ b/TUnit.Assertions/Helpers/Formatter.cs
@@ -27,8 +27,10 @@ public override string FormatValue(object? value)
new SimpleFormatter(value => $"'{value}'"),
new SimpleFormatter(value => $"<{value:O}>"),
new SimpleFormatter(value => value.ToString("", CultureInfo.InvariantCulture)),
+#if NET
new SimpleFormatter(value => value.ToString("", CultureInfo.InvariantCulture)),
new SimpleFormatter(value => value.ToString("", CultureInfo.InvariantCulture)),
+#endif
new SimpleFormatter(value => $"[{string.Join(", ", value.Cast |