diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet10_0.verified.txt index 2789051204..67fe2526b6 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions /// public static DefaultValuesAssertion HasDefaultValues(this IAssertionSource source, bool boolValue = true, int intValue = 0, string stringValue = "default", [CallerArgumentExpression(nameof(boolValue))] string? boolValueExpression = null, [CallerArgumentExpression(nameof(intValue))] string? intValueExpression = null, [CallerArgumentExpression(nameof(stringValue))] string? stringValueExpression = null) { - source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})"); + source.Context.ExpressionBuilder.Append(".HasDefaultValues(" + + string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")"); return new DefaultValuesAssertion(source.Context, boolValue, intValue, stringValue); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet8_0.verified.txt index 2789051204..67fe2526b6 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions /// public static DefaultValuesAssertion HasDefaultValues(this IAssertionSource source, bool boolValue = true, int intValue = 0, string stringValue = "default", [CallerArgumentExpression(nameof(boolValue))] string? boolValueExpression = null, [CallerArgumentExpression(nameof(intValue))] string? intValueExpression = null, [CallerArgumentExpression(nameof(stringValue))] string? stringValueExpression = null) { - source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})"); + source.Context.ExpressionBuilder.Append(".HasDefaultValues(" + + string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")"); return new DefaultValuesAssertion(source.Context, boolValue, intValue, stringValue); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet9_0.verified.txt index 2789051204..67fe2526b6 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions /// public static DefaultValuesAssertion HasDefaultValues(this IAssertionSource source, bool boolValue = true, int intValue = 0, string stringValue = "default", [CallerArgumentExpression(nameof(boolValue))] string? boolValueExpression = null, [CallerArgumentExpression(nameof(intValue))] string? intValueExpression = null, [CallerArgumentExpression(nameof(stringValue))] string? stringValueExpression = null) { - source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})"); + source.Context.ExpressionBuilder.Append(".HasDefaultValues(" + + string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")"); return new DefaultValuesAssertion(source.Context, boolValue, intValue, stringValue); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.Net4_7.verified.txt index 2789051204..67fe2526b6 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions /// public static DefaultValuesAssertion HasDefaultValues(this IAssertionSource source, bool boolValue = true, int intValue = 0, string stringValue = "default", [CallerArgumentExpression(nameof(boolValue))] string? boolValueExpression = null, [CallerArgumentExpression(nameof(intValue))] string? intValueExpression = null, [CallerArgumentExpression(nameof(stringValue))] string? stringValueExpression = null) { - source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})"); + source.Context.ExpressionBuilder.Append(".HasDefaultValues(" + + string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")"); return new DefaultValuesAssertion(source.Context, boolValue, intValue, stringValue); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet10_0.verified.txt index 7feb94b908..81fa22380f 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions /// /// Extension method for StringComparisonAssertion. /// - public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) + public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison(" + + string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")"); return new StringComparisonAssertion(source.Context, expected, comparison); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet8_0.verified.txt index 7feb94b908..81fa22380f 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions /// /// Extension method for StringComparisonAssertion. /// - public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) + public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison(" + + string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")"); return new StringComparisonAssertion(source.Context, expected, comparison); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet9_0.verified.txt index 7feb94b908..81fa22380f 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions /// /// Extension method for StringComparisonAssertion. /// - public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) + public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison(" + + string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")"); return new StringComparisonAssertion(source.Context, expected, comparison); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.Net4_7.verified.txt index 7feb94b908..81fa22380f 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions /// /// Extension method for StringComparisonAssertion. /// - public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) + public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison(" + + string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")"); return new StringComparisonAssertion(source.Context, expected, comparison); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet10_0.verified.txt index 96d04a72e4..a1ba8eb1f7 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class GreaterThanAssertionExtensions public static GreaterThanAssertion IsGreaterThan(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsGreaterThan({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsGreaterThan(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new GreaterThanAssertion(source.Context, expected); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet8_0.verified.txt index 96d04a72e4..a1ba8eb1f7 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class GreaterThanAssertionExtensions public static GreaterThanAssertion IsGreaterThan(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsGreaterThan({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsGreaterThan(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new GreaterThanAssertion(source.Context, expected); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet9_0.verified.txt index 96d04a72e4..a1ba8eb1f7 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class GreaterThanAssertionExtensions public static GreaterThanAssertion IsGreaterThan(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsGreaterThan({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsGreaterThan(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new GreaterThanAssertion(source.Context, expected); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.Net4_7.verified.txt index 96d04a72e4..a1ba8eb1f7 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class GreaterThanAssertionExtensions public static GreaterThanAssertion IsGreaterThan(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsGreaterThan({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsGreaterThan(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new GreaterThanAssertion(source.Context, expected); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet10_0.verified.txt index f43d45e395..f545812480 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected); } @@ -28,7 +30,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, System.Collections.Generic.IEqualityComparer comparer, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet8_0.verified.txt index f43d45e395..f545812480 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected); } @@ -28,7 +30,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, System.Collections.Generic.IEqualityComparer comparer, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet9_0.verified.txt index f43d45e395..f545812480 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected); } @@ -28,7 +30,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, System.Collections.Generic.IEqualityComparer comparer, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.Net4_7.verified.txt index f43d45e395..f545812480 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleConstructors.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected); } @@ -28,7 +30,8 @@ public static class EqualsAssertionExtensions /// public static EqualsAssertion IsEqualTo(this IAssertionSource source, TValue expected, System.Collections.Generic.IEqualityComparer comparer, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsEqualTo({expectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsEqualTo(" + + string.Join(", ", new[] { expectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new EqualsAssertion(source.Context, expected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet10_0.verified.txt index fd7d9c4ade..cf3c4fd8cf 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class BetweenAssertionExtensions public static BetweenAssertion IsBetween(this IAssertionSource source, TValue lowerBound, TValue upperBound, [CallerArgumentExpression(nameof(lowerBound))] string? lowerBoundExpression = null, [CallerArgumentExpression(nameof(upperBound))] string? upperBoundExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsBetween({lowerBoundExpression}, {upperBoundExpression})"); + source.Context.ExpressionBuilder.Append(".IsBetween(" + + string.Join(", ", new[] { lowerBoundExpression, upperBoundExpression }.Where(e => e != null)) + ")"); return new BetweenAssertion(source.Context, lowerBound, upperBound); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet8_0.verified.txt index fd7d9c4ade..cf3c4fd8cf 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class BetweenAssertionExtensions public static BetweenAssertion IsBetween(this IAssertionSource source, TValue lowerBound, TValue upperBound, [CallerArgumentExpression(nameof(lowerBound))] string? lowerBoundExpression = null, [CallerArgumentExpression(nameof(upperBound))] string? upperBoundExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsBetween({lowerBoundExpression}, {upperBoundExpression})"); + source.Context.ExpressionBuilder.Append(".IsBetween(" + + string.Join(", ", new[] { lowerBoundExpression, upperBoundExpression }.Where(e => e != null)) + ")"); return new BetweenAssertion(source.Context, lowerBound, upperBound); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet9_0.verified.txt index fd7d9c4ade..cf3c4fd8cf 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class BetweenAssertionExtensions public static BetweenAssertion IsBetween(this IAssertionSource source, TValue lowerBound, TValue upperBound, [CallerArgumentExpression(nameof(lowerBound))] string? lowerBoundExpression = null, [CallerArgumentExpression(nameof(upperBound))] string? upperBoundExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsBetween({lowerBoundExpression}, {upperBoundExpression})"); + source.Context.ExpressionBuilder.Append(".IsBetween(" + + string.Join(", ", new[] { lowerBoundExpression, upperBoundExpression }.Where(e => e != null)) + ")"); return new BetweenAssertion(source.Context, lowerBound, upperBound); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.Net4_7.verified.txt index fd7d9c4ade..cf3c4fd8cf 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithMultipleParameters.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -20,7 +21,8 @@ public static class BetweenAssertionExtensions public static BetweenAssertion IsBetween(this IAssertionSource source, TValue lowerBound, TValue upperBound, [CallerArgumentExpression(nameof(lowerBound))] string? lowerBoundExpression = null, [CallerArgumentExpression(nameof(upperBound))] string? upperBoundExpression = null) where TValue : System.IComparable { - source.Context.ExpressionBuilder.Append($".IsBetween({lowerBoundExpression}, {upperBoundExpression})"); + source.Context.ExpressionBuilder.Append(".IsBetween(" + + string.Join(", ", new[] { lowerBoundExpression, upperBoundExpression }.Where(e => e != null)) + ")"); return new BetweenAssertion(source.Context, lowerBound, upperBound); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet10_0.verified.txt index 74801947d8..b2dc0a61f1 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsTrue(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsTrue()"); + source.Context.ExpressionBuilder.Append(".IsTrue(" + ")"); return new TrueAssertion(source.Context); } @@ -28,7 +29,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsFalse(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsFalse()"); + source.Context.ExpressionBuilder.Append(".IsFalse(" + ")"); return new TrueAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet8_0.verified.txt index 74801947d8..b2dc0a61f1 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsTrue(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsTrue()"); + source.Context.ExpressionBuilder.Append(".IsTrue(" + ")"); return new TrueAssertion(source.Context); } @@ -28,7 +29,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsFalse(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsFalse()"); + source.Context.ExpressionBuilder.Append(".IsFalse(" + ")"); return new TrueAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet9_0.verified.txt index 74801947d8..b2dc0a61f1 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsTrue(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsTrue()"); + source.Context.ExpressionBuilder.Append(".IsTrue(" + ")"); return new TrueAssertion(source.Context); } @@ -28,7 +29,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsFalse(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsFalse()"); + source.Context.ExpressionBuilder.Append(".IsFalse(" + ")"); return new TrueAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.Net4_7.verified.txt index 74801947d8..b2dc0a61f1 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithNegatedMethod.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsTrue(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsTrue()"); + source.Context.ExpressionBuilder.Append(".IsTrue(" + ")"); return new TrueAssertion(source.Context); } @@ -28,7 +29,7 @@ public static class TrueAssertionExtensions /// public static TrueAssertion IsFalse(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsFalse()"); + source.Context.ExpressionBuilder.Append(".IsFalse(" + ")"); return new TrueAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet10_0.verified.txt index 38721800fe..9ccf7cf5b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class NotEqualsAssertionExtensions /// public static NotEqualsAssertion IsNotEqualTo(this IAssertionSource source, TValue notExpected, System.Collections.Generic.IEqualityComparer? comparer = null, [CallerArgumentExpression(nameof(notExpected))] string? notExpectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsNotEqualTo({notExpectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsNotEqualTo(" + + string.Join(", ", new[] { notExpectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new NotEqualsAssertion(source.Context, notExpected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet8_0.verified.txt index 38721800fe..9ccf7cf5b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class NotEqualsAssertionExtensions /// public static NotEqualsAssertion IsNotEqualTo(this IAssertionSource source, TValue notExpected, System.Collections.Generic.IEqualityComparer? comparer = null, [CallerArgumentExpression(nameof(notExpected))] string? notExpectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsNotEqualTo({notExpectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsNotEqualTo(" + + string.Join(", ", new[] { notExpectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new NotEqualsAssertion(source.Context, notExpected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet9_0.verified.txt index 38721800fe..9ccf7cf5b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class NotEqualsAssertionExtensions /// public static NotEqualsAssertion IsNotEqualTo(this IAssertionSource source, TValue notExpected, System.Collections.Generic.IEqualityComparer? comparer = null, [CallerArgumentExpression(nameof(notExpected))] string? notExpectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsNotEqualTo({notExpectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsNotEqualTo(" + + string.Join(", ", new[] { notExpectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new NotEqualsAssertion(source.Context, notExpected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.Net4_7.verified.txt index 38721800fe..9ccf7cf5b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithOptionalParameter.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,8 @@ public static class NotEqualsAssertionExtensions /// public static NotEqualsAssertion IsNotEqualTo(this IAssertionSource source, TValue notExpected, System.Collections.Generic.IEqualityComparer? comparer = null, [CallerArgumentExpression(nameof(notExpected))] string? notExpectedExpression = null, [CallerArgumentExpression(nameof(comparer))] string? comparerExpression = null) { - source.Context.ExpressionBuilder.Append($".IsNotEqualTo({notExpectedExpression}, {comparerExpression})"); + source.Context.ExpressionBuilder.Append(".IsNotEqualTo(" + + string.Join(", ", new[] { notExpectedExpression, comparerExpression }.Where(e => e != null)) + ")"); return new NotEqualsAssertion(source.Context, notExpected, comparer); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet10_0.verified.txt index 0e082051dd..64576dd105 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class IsAssignableToAssertionExtensions /// public static IsAssignableToAssertion IsAssignableTo(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsAssignableTo()"); + source.Context.ExpressionBuilder.Append(".IsAssignableTo(" + ")"); return new IsAssignableToAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet8_0.verified.txt index 0e082051dd..64576dd105 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class IsAssignableToAssertionExtensions /// public static IsAssignableToAssertion IsAssignableTo(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsAssignableTo()"); + source.Context.ExpressionBuilder.Append(".IsAssignableTo(" + ")"); return new IsAssignableToAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet9_0.verified.txt index 0e082051dd..64576dd105 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class IsAssignableToAssertionExtensions /// public static IsAssignableToAssertion IsAssignableTo(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsAssignableTo()"); + source.Context.ExpressionBuilder.Append(".IsAssignableTo(" + ")"); return new IsAssignableToAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.Net4_7.verified.txt index 0e082051dd..64576dd105 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.MultipleGenericParameters.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class IsAssignableToAssertionExtensions /// public static IsAssignableToAssertion IsAssignableTo(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsAssignableTo()"); + source.Context.ExpressionBuilder.Append(".IsAssignableTo(" + ")"); return new IsAssignableToAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet10_0.verified.txt index 5a77024fe7..e94665f00a 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class StringIsEmptyAssertionExtensions /// public static StringIsEmptyAssertion IsEmpty(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsEmpty()"); + source.Context.ExpressionBuilder.Append(".IsEmpty(" + ")"); return new StringIsEmptyAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet8_0.verified.txt index 5a77024fe7..e94665f00a 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class StringIsEmptyAssertionExtensions /// public static StringIsEmptyAssertion IsEmpty(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsEmpty()"); + source.Context.ExpressionBuilder.Append(".IsEmpty(" + ")"); return new StringIsEmptyAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet9_0.verified.txt index 5a77024fe7..e94665f00a 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class StringIsEmptyAssertionExtensions /// public static StringIsEmptyAssertion IsEmpty(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsEmpty()"); + source.Context.ExpressionBuilder.Append(".IsEmpty(" + ")"); return new StringIsEmptyAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.Net4_7.verified.txt index 5a77024fe7..e94665f00a 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.NonGenericAssertion.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class StringIsEmptyAssertionExtensions /// public static StringIsEmptyAssertion IsEmpty(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsEmpty()"); + source.Context.ExpressionBuilder.Append(".IsEmpty(" + ")"); return new StringIsEmptyAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet10_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet10_0.verified.txt index 110bb7c5c0..cb5f1ba8b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet10_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet10_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class NullAssertionExtensions /// public static NullAssertion IsNull(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsNull()"); + source.Context.ExpressionBuilder.Append(".IsNull(" + ")"); return new NullAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet8_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet8_0.verified.txt index 110bb7c5c0..cb5f1ba8b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet8_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet8_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class NullAssertionExtensions /// public static NullAssertion IsNull(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsNull()"); + source.Context.ExpressionBuilder.Append(".IsNull(" + ")"); return new NullAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet9_0.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet9_0.verified.txt index 110bb7c5c0..cb5f1ba8b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet9_0.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.DotNet9_0.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class NullAssertionExtensions /// public static NullAssertion IsNull(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsNull()"); + source.Context.ExpressionBuilder.Append(".IsNull(" + ")"); return new NullAssertion(source.Context); } } diff --git a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.Net4_7.verified.txt b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.Net4_7.verified.txt index 110bb7c5c0..cb5f1ba8b5 100644 --- a/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.Net4_7.verified.txt +++ b/TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.SingleGenericParameter.Net4_7.verified.txt @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using TUnit.Assertions.Core; +using TUnit.Assertions.Enums; using TUnit.Assertions.Tests.TestData; namespace TUnit.Assertions.Extensions; @@ -19,7 +20,7 @@ public static class NullAssertionExtensions /// public static NullAssertion IsNull(this IAssertionSource source) { - source.Context.ExpressionBuilder.Append($".IsNull()"); + source.Context.ExpressionBuilder.Append(".IsNull(" + ")"); return new NullAssertion(source.Context); } } diff --git a/TUnit.Assertions.Tests/BooleanAssertionTests.cs b/TUnit.Assertions.Tests/BooleanAssertionTests.cs index c7c3286559..6c07e50781 100644 --- a/TUnit.Assertions.Tests/BooleanAssertionTests.cs +++ b/TUnit.Assertions.Tests/BooleanAssertionTests.cs @@ -32,4 +32,50 @@ public async Task Test_Boolean_IsFalse_FromExpression() var result = 5 < 3; await Assert.That(result).IsFalse(); } + + [Test] + public async Task Test_NullableBoolean_IsTrue_WithTrue() + { + bool? value = true; + await Assert.That(value).IsTrue(); + } + + [Test] + public async Task Test_NullableBoolean_IsTrue_WithFalse() + { + bool? value = false; + await Assert.That(async () => await Assert.That(value).IsTrue()) + .Throws(); + } + + [Test] + public async Task Test_NullableBoolean_IsTrue_WithNull() + { + bool? value = null; + await Assert.That(async () => await Assert.That(value).IsTrue()) + .Throws(); + } + + [Test] + public async Task Test_NullableBoolean_IsFalse_WithFalse() + { + bool? value = false; + await Assert.That(value).IsFalse(); + } + + [Test] + public async Task Test_NullableBoolean_IsFalse_WithTrue() + { + bool? value = true; + await Assert.That(async () => await Assert.That(value).IsFalse()) + .Throws(); + } + + [Test] + public async Task Test_NullableBoolean_IsFalse_WithNull() + { + bool? value = null; + await Assert.That(async () => await Assert.That(value).IsFalse()) + .Throws(); + } } diff --git a/TUnit.Assertions.Tests/Old/DefaultAssertionTests.cs b/TUnit.Assertions.Tests/Old/DefaultAssertionTests.cs index 3ad864670c..25832aa3b6 100644 --- a/TUnit.Assertions.Tests/Old/DefaultAssertionTests.cs +++ b/TUnit.Assertions.Tests/Old/DefaultAssertionTests.cs @@ -69,4 +69,79 @@ public async Task IsNotDefault_ValueType_DateTime_NotDefault() var dt = DateTime.Now; await TUnitAssert.That(dt).IsNotDefault(); } + + [Test] + public async Task IsDefault_ReferenceType_String_Null() + { + string? str = null; + await TUnitAssert.That(str).IsDefault(); + } + + [Test] + public async Task IsDefault_ReferenceType_String_NotNull() + { + await TUnitAssert.That(async () => + { + string str = "Hello"; + await TUnitAssert.That(str).IsDefault(); + }).Throws(); + } + + [Test] + public async Task IsDefault_ReferenceType_Object_Null() + { + object? obj = null; + await TUnitAssert.That(obj).IsDefault(); + } + + [Test] + public async Task IsDefault_ReferenceType_Object_NotNull() + { + await TUnitAssert.That(async () => + { + object obj = new object(); + await TUnitAssert.That(obj).IsDefault(); + }).Throws(); + } + + [Test] + public async Task IsNotDefault_ReferenceType_String_Null() + { + await TUnitAssert.That(async () => + { + string? str = null; + await TUnitAssert.That(str).IsNotDefault(); + }).Throws(); + } + + [Test] + public async Task IsNotDefault_ReferenceType_String_NotNull() + { + string str = "Hello"; + await TUnitAssert.That(str).IsNotDefault(); + } + + [Test] + public async Task IsNotDefault_ReferenceType_String_Empty() + { + string str = ""; + await TUnitAssert.That(str).IsNotDefault(); + } + + [Test] + public async Task IsNotDefault_ReferenceType_Object_Null() + { + await TUnitAssert.That(async () => + { + object? obj = null; + await TUnitAssert.That(obj).IsNotDefault(); + }).Throws(); + } + + [Test] + public async Task IsNotDefault_ReferenceType_Object_NotNull() + { + object obj = new object(); + await TUnitAssert.That(obj).IsNotDefault(); + } } diff --git a/TUnit.Assertions.Tests/StringNullabilityAssertionTests.cs b/TUnit.Assertions.Tests/StringNullabilityAssertionTests.cs index 45c7b48969..2456ef9e74 100644 --- a/TUnit.Assertions.Tests/StringNullabilityAssertionTests.cs +++ b/TUnit.Assertions.Tests/StringNullabilityAssertionTests.cs @@ -88,4 +88,42 @@ public async Task IsNotNullOrEmpty_WithNonEmptyString_Passes() var value = "Hello"; await Assert.That(value).IsNotNullOrEmpty(); } + + [Test] + public async Task IsNotNullOrWhiteSpace_WithNullString_Fails() + { + string? nullString = null; + await Assert.That(async () => await Assert.That(nullString).IsNotNullOrWhiteSpace()) + .Throws(); + } + + [Test] + public async Task IsNotNullOrWhiteSpace_WithEmptyString_Fails() + { + var emptyString = ""; + await Assert.That(async () => await Assert.That(emptyString).IsNotNullOrWhiteSpace()) + .Throws(); + } + + [Test] + public async Task IsNotNullOrWhiteSpace_WithWhitespace_Fails() + { + var whitespace = " "; + await Assert.That(async () => await Assert.That(whitespace).IsNotNullOrWhiteSpace()) + .Throws(); + } + + [Test] + public async Task IsNotNullOrWhiteSpace_WithNonEmptyString_Passes() + { + var value = "Hello"; + await Assert.That(value).IsNotNullOrWhiteSpace(); + } + + [Test] + public async Task IsNotNullOrWhiteSpace_WithStringContainingWhitespace_Passes() + { + var value = "Hello World"; + await Assert.That(value).IsNotNullOrWhiteSpace(); + } } diff --git a/TUnit.Assertions/Conditions/BooleanAssertionExtensions.cs b/TUnit.Assertions/Conditions/BooleanAssertionExtensions.cs index 307c998abb..d615a08a02 100644 --- a/TUnit.Assertions/Conditions/BooleanAssertionExtensions.cs +++ b/TUnit.Assertions/Conditions/BooleanAssertionExtensions.cs @@ -16,4 +16,12 @@ public static partial class BooleanAssertionExtensions [EditorBrowsable(EditorBrowsableState.Never)] [GenerateAssertion(ExpectationMessage = "to be false")] public static bool IsFalse(this bool value) => value == false; + + [EditorBrowsable(EditorBrowsableState.Never)] + [GenerateAssertion(ExpectationMessage = "to be true")] + public static bool IsTrue(this bool? value) => value == true; + + [EditorBrowsable(EditorBrowsableState.Never)] + [GenerateAssertion(ExpectationMessage = "to be false")] + public static bool IsFalse(this bool? value) => value == false; } diff --git a/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs b/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs index 12d6938a75..d78a86b509 100644 --- a/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs +++ b/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs @@ -5,17 +5,18 @@ namespace TUnit.Assertions.Conditions; /// /// Asserts that a collection contains only distinct (unique) items. +/// Inherits from CollectionAssertionBase to enable chaining of collection methods. /// -public class HasDistinctItemsAssertion : Assertion - where TValue : System.Collections.IEnumerable +public class HasDistinctItemsAssertion : Sources.CollectionAssertionBase + where TCollection : IEnumerable { public HasDistinctItemsAssertion( - AssertionContext context) + AssertionContext context) : base(context) { } - protected override Task CheckAsync(EvaluationMetadata metadata) + protected override Task CheckAsync(EvaluationMetadata metadata) { var value = metadata.Value; var exception = metadata.Exception; @@ -30,7 +31,7 @@ protected override Task CheckAsync(EvaluationMetadata m return Task.FromResult(AssertionResult.Failed("collection was null")); } - var list = value.Cast().ToList(); + var list = value.ToList(); var distinctList = list.Distinct().ToList(); if (list.Count == distinctList.Count) diff --git a/TUnit.Assertions/Conditions/NullAssertion.cs b/TUnit.Assertions/Conditions/NullAssertion.cs index cce03ee71f..9560816bd2 100644 --- a/TUnit.Assertions/Conditions/NullAssertion.cs +++ b/TUnit.Assertions/Conditions/NullAssertion.cs @@ -137,3 +137,71 @@ protected override Task CheckAsync(EvaluationMetadata m protected override string GetExpectation() => $"to not be default({typeof(TValue).Name})"; } + +/// +/// Asserts that a reference type value is equal to the default value (null). +/// For reference types, this is equivalent to IsNull(). +/// +[AssertionExtension("IsDefault")] +public class IsDefaultReferenceAssertion : Assertion where TValue : class +{ + public IsDefaultReferenceAssertion( + AssertionContext context) + : base(context) + { + } + + protected override Task CheckAsync(EvaluationMetadata metadata) + { + var value = metadata.Value; + var exception = metadata.Exception; + + if (exception != null) + { + return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().Name}")); + } + + if (EqualityComparer.Default.Equals(value!, default!)) + { + return Task.FromResult(AssertionResult.Passed); + } + + return Task.FromResult(AssertionResult.Failed($"value is {value}")); + } + + protected override string GetExpectation() => $"to be default({typeof(TValue).Name})"; +} + +/// +/// Asserts that a reference type value is not the default value (not null). +/// For reference types, this is equivalent to IsNotNull(). +/// +[AssertionExtension("IsNotDefault")] +public class IsNotDefaultReferenceAssertion : Assertion where TValue : class +{ + public IsNotDefaultReferenceAssertion( + AssertionContext context) + : base(context) + { + } + + protected override Task CheckAsync(EvaluationMetadata metadata) + { + var value = metadata.Value; + var exception = metadata.Exception; + + if (exception != null) + { + return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().Name}")); + } + + if (!EqualityComparer.Default.Equals(value!, default!)) + { + return Task.FromResult(AssertionResult.Passed); + } + + return Task.FromResult(AssertionResult.Failed($"value is default({typeof(TValue).Name})")); + } + + protected override string GetExpectation() => $"to not be default({typeof(TValue).Name})"; +} diff --git a/TUnit.Assertions/Conditions/StringStaticMethodAssertions.cs b/TUnit.Assertions/Conditions/StringStaticMethodAssertions.cs index 681a1e253c..d442736372 100644 --- a/TUnit.Assertions/Conditions/StringStaticMethodAssertions.cs +++ b/TUnit.Assertions/Conditions/StringStaticMethodAssertions.cs @@ -9,6 +9,7 @@ namespace TUnit.Assertions.Conditions; [AssertionFrom(nameof(string.IsNullOrWhiteSpace), ExpectationMessage = "be null, empty, or whitespace")] [AssertionFrom(nameof(string.IsNullOrEmpty), ExpectationMessage = "be null or empty")] [AssertionFrom(nameof(string.IsNullOrEmpty), CustomName = "IsNotNullOrEmpty", NegateLogic = true, ExpectationMessage = "be null or empty")] +[AssertionFrom(nameof(string.IsNullOrWhiteSpace), CustomName = "IsNotNullOrWhiteSpace", NegateLogic = true, ExpectationMessage = "be null, empty, or whitespace")] public static partial class StringStaticMethodAssertions { } diff --git a/TUnit.Assertions/Extensions/AssertionExtensions.cs b/TUnit.Assertions/Extensions/AssertionExtensions.cs index bd802309f4..77afdb4864 100644 --- a/TUnit.Assertions/Extensions/AssertionExtensions.cs +++ b/TUnit.Assertions/Extensions/AssertionExtensions.cs @@ -355,17 +355,6 @@ public static StringLengthAssertion HasLength( // from the collection assertion classes decorated with [AssertionExtension] attributes. // This eliminates the need for manual overloads with OverloadResolutionPriority workarounds. - /// - /// Asserts that the collection contains only distinct (unique) items. - /// - public static HasDistinctItemsAssertion HasDistinctItems( - this IAssertionSource source) - where TValue : IEnumerable - { - source.Context.ExpressionBuilder.Append(".HasDistinctItems()"); - return new HasDistinctItemsAssertion(source.Context); - } - // Collection equivalence assertions (IsEquivalentTo/IsNotEquivalentTo for IEnumerable) // are now generated by AssertionExtensionGenerator. // Use .Using(comparer) to specify a custom equality comparer. diff --git a/TUnit.Assertions/Sources/CollectionAssertionBase.cs b/TUnit.Assertions/Sources/CollectionAssertionBase.cs index a67a5878ee..90c107b219 100644 --- a/TUnit.Assertions/Sources/CollectionAssertionBase.cs +++ b/TUnit.Assertions/Sources/CollectionAssertionBase.cs @@ -218,6 +218,17 @@ public HasSingleItemAssertion HasSingleItem() return new HasSingleItemAssertion(Context); } + /// + /// Asserts that the collection contains only distinct (unique) items. + /// This instance method enables calling HasDistinctItems with proper type inference. + /// Example: await Assert.That(list).HasDistinctItems(); + /// + public HasDistinctItemsAssertion HasDistinctItems() + { + Context.ExpressionBuilder.Append(".HasDistinctItems()"); + return new HasDistinctItemsAssertion(Context); + } + /// /// Asserts that the collection does not contain the specified item. /// This instance method enables calling DoesNotContain with proper type inference. diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt index 02dcf51778..f2c9fbef12 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt @@ -323,8 +323,12 @@ namespace .Conditions { [.(ExpectationMessage="to be false")] public static bool IsFalse(this bool value) { } + [.(ExpectationMessage="to be false")] + public static bool IsFalse(this bool? value) { } [.(ExpectationMessage="to be true")] public static bool IsTrue(this bool value) { } + [.(ExpectationMessage="to be true")] + public static bool IsTrue(this bool? value) { } } [.<.CancellationToken>("CanBeCanceled", CustomName="CannotBeCanceled", ExpectationMessage="be cancellable", NegateLogic=true)] [.<.CancellationToken>("CanBeCanceled", ExpectationMessage="be cancellable")] @@ -900,11 +904,11 @@ namespace .Conditions [.(ExpectationMessage="to not be an empty GUID")] public static bool IsNotEmptyGuid(this value) { } } - public class HasDistinctItemsAssertion : . - where TValue : .IEnumerable + public class HasDistinctItemsAssertion : . + where TCollection : . { - public HasDistinctItemsAssertion(. context) { } - protected override .<.> CheckAsync(. metadata) { } + public HasDistinctItemsAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } public class HasMessageContainingAssertion : . @@ -988,6 +992,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsDefault")] + public class IsDefaultReferenceAssertion : . + where TValue : class + { + public IsDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsEquatableOrEqualTo")] public class IsEquatableOrEqualToAssertion : . { @@ -1032,6 +1044,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsNotDefault")] + public class IsNotDefaultReferenceAssertion : . + where TValue : class + { + public IsNotDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsNotIn")] public class IsNotInAssertion : . { @@ -1308,6 +1328,7 @@ namespace .Conditions } [.("IsNullOrEmpty", CustomName="IsNotNullOrEmpty", ExpectationMessage="be null or empty", NegateLogic=true)] [.("IsNullOrEmpty", ExpectationMessage="be null or empty")] + [.("IsNullOrWhiteSpace", CustomName="IsNotNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace", NegateLogic=true)] [.("IsNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace")] public static class StringStaticMethodAssertions { } public class StructuralEquivalencyAssertion : . @@ -1777,8 +1798,6 @@ namespace .Extensions public static ..DoesNotHaveSameValueAsAssertion DoesNotHaveSameValueAs(this . source, otherEnumValue, [.("otherEnumValue")] string? expression = null) where TEnum : struct, { } public static . EqualTo(this . source, TValue? expected, [.("expected")] string? expression = null) { } - public static . HasDistinctItems(this . source) - where TValue : .IEnumerable { } public static ..HasFlagAssertion HasFlag(this . source, TEnum expectedFlag, [.("expectedFlag")] string? expression = null) where TEnum : struct, { } public static ..LengthWrapper HasLength(this . source) { } @@ -1902,7 +1921,9 @@ namespace .Extensions public static class BooleanAssertionExtensions { public static ._IsFalse_Assertion IsFalse(this . source) { } + public static ._IsFalse_Assertion IsFalse(this . source) { } public static ._IsTrue_Assertion IsTrue(this . source) { } + public static ._IsTrue_Assertion IsTrue(this . source) { } } public static class CancellationTokenAssertionExtensions { @@ -2952,6 +2973,11 @@ namespace .Extensions public static . IsDefault(this . source) where TValue : struct { } } + public static class IsDefaultReferenceAssertionExtensions + { + public static . IsDefault(this . source) + where TValue : class { } + } public static class IsEquatableOrEqualToAssertionExtensions { public static . IsEquatableOrEqualTo(this . source, TValue expected, [.("expected")] string? expectedExpression = null) { } @@ -2980,6 +3006,11 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : struct { } } + public static class IsNotDefaultReferenceAssertionExtensions + { + public static . IsNotDefault(this . source) + where TValue : class { } + } public static class IsNotInAssertionExtensions { public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } @@ -3039,6 +3070,18 @@ namespace .Extensions { public static . IsNull(this . source) { } } + public sealed class NullableBool_IsFalse_Assertion : . + { + public NullableBool_IsFalse_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class NullableBool_IsTrue_Assertion : . + { + public NullableBool_IsTrue_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class NullableEquatableAssertionExtensions { public static . IsEquatableTo(this . source, TExpected expected, [.("expected")] string? expectedExpression = null) @@ -3256,6 +3299,7 @@ namespace .Extensions public static class StringStaticMethodAssertions { public static . IsNotNullOrEmpty(this . source) { } + public static . IsNotNullOrWhiteSpace(this . source) { } public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } @@ -3837,6 +3881,7 @@ namespace .Sources protected override string GetExpectation() { } public ..CountWrapper HasCount() { } public . HasCount(int expectedCount, [.("expectedCount")] string? expression = null) { } + public . HasDistinctItems() { } public . HasSingleItem() { } public . IsEmpty() { } public . IsInDescendingOrder() { } diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt index 35f3a409e5..242223f761 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt @@ -320,8 +320,12 @@ namespace .Conditions { [.(ExpectationMessage="to be false")] public static bool IsFalse(this bool value) { } + [.(ExpectationMessage="to be false")] + public static bool IsFalse(this bool? value) { } [.(ExpectationMessage="to be true")] public static bool IsTrue(this bool value) { } + [.(ExpectationMessage="to be true")] + public static bool IsTrue(this bool? value) { } } [.<.CancellationToken>("CanBeCanceled", CustomName="CannotBeCanceled", ExpectationMessage="be cancellable", NegateLogic=true)] [.<.CancellationToken>("CanBeCanceled", ExpectationMessage="be cancellable")] @@ -897,11 +901,11 @@ namespace .Conditions [.(ExpectationMessage="to not be an empty GUID")] public static bool IsNotEmptyGuid(this value) { } } - public class HasDistinctItemsAssertion : . - where TValue : .IEnumerable + public class HasDistinctItemsAssertion : . + where TCollection : . { - public HasDistinctItemsAssertion(. context) { } - protected override .<.> CheckAsync(. metadata) { } + public HasDistinctItemsAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } public class HasMessageContainingAssertion : . @@ -985,6 +989,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsDefault")] + public class IsDefaultReferenceAssertion : . + where TValue : class + { + public IsDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsEquatableOrEqualTo")] public class IsEquatableOrEqualToAssertion : . { @@ -1029,6 +1041,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsNotDefault")] + public class IsNotDefaultReferenceAssertion : . + where TValue : class + { + public IsNotDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsNotIn")] public class IsNotInAssertion : . { @@ -1305,6 +1325,7 @@ namespace .Conditions } [.("IsNullOrEmpty", CustomName="IsNotNullOrEmpty", ExpectationMessage="be null or empty", NegateLogic=true)] [.("IsNullOrEmpty", ExpectationMessage="be null or empty")] + [.("IsNullOrWhiteSpace", CustomName="IsNotNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace", NegateLogic=true)] [.("IsNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace")] public static class StringStaticMethodAssertions { } public class StructuralEquivalencyAssertion : . @@ -1774,8 +1795,6 @@ namespace .Extensions public static ..DoesNotHaveSameValueAsAssertion DoesNotHaveSameValueAs(this . source, otherEnumValue, [.("otherEnumValue")] string? expression = null) where TEnum : struct, { } public static . EqualTo(this . source, TValue? expected, [.("expected")] string? expression = null) { } - public static . HasDistinctItems(this . source) - where TValue : .IEnumerable { } public static ..HasFlagAssertion HasFlag(this . source, TEnum expectedFlag, [.("expectedFlag")] string? expression = null) where TEnum : struct, { } public static ..LengthWrapper HasLength(this . source) { } @@ -1899,7 +1918,9 @@ namespace .Extensions public static class BooleanAssertionExtensions { public static ._IsFalse_Assertion IsFalse(this . source) { } + public static ._IsFalse_Assertion IsFalse(this . source) { } public static ._IsTrue_Assertion IsTrue(this . source) { } + public static ._IsTrue_Assertion IsTrue(this . source) { } } public static class CancellationTokenAssertionExtensions { @@ -2943,6 +2964,11 @@ namespace .Extensions public static . IsDefault(this . source) where TValue : struct { } } + public static class IsDefaultReferenceAssertionExtensions + { + public static . IsDefault(this . source) + where TValue : class { } + } public static class IsEquatableOrEqualToAssertionExtensions { public static . IsEquatableOrEqualTo(this . source, TValue expected, [.("expected")] string? expectedExpression = null) { } @@ -2971,6 +2997,11 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : struct { } } + public static class IsNotDefaultReferenceAssertionExtensions + { + public static . IsNotDefault(this . source) + where TValue : class { } + } public static class IsNotInAssertionExtensions { public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } @@ -3029,6 +3060,18 @@ namespace .Extensions { public static . IsNull(this . source) { } } + public sealed class NullableBool_IsFalse_Assertion : . + { + public NullableBool_IsFalse_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class NullableBool_IsTrue_Assertion : . + { + public NullableBool_IsTrue_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class NullableEquatableAssertionExtensions { public static . IsEquatableTo(this . source, TExpected expected, [.("expected")] string? expectedExpression = null) @@ -3245,6 +3288,7 @@ namespace .Extensions public static class StringStaticMethodAssertions { public static . IsNotNullOrEmpty(this . source) { } + public static . IsNotNullOrWhiteSpace(this . source) { } public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } @@ -3824,6 +3868,7 @@ namespace .Sources protected override string GetExpectation() { } public ..CountWrapper HasCount() { } public . HasCount(int expectedCount, [.("expectedCount")] string? expression = null) { } + public . HasDistinctItems() { } public . HasSingleItem() { } public . IsEmpty() { } public . IsInDescendingOrder() { } diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt index d0f8e8b482..c226b2eb85 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt @@ -323,8 +323,12 @@ namespace .Conditions { [.(ExpectationMessage="to be false")] public static bool IsFalse(this bool value) { } + [.(ExpectationMessage="to be false")] + public static bool IsFalse(this bool? value) { } [.(ExpectationMessage="to be true")] public static bool IsTrue(this bool value) { } + [.(ExpectationMessage="to be true")] + public static bool IsTrue(this bool? value) { } } [.<.CancellationToken>("CanBeCanceled", CustomName="CannotBeCanceled", ExpectationMessage="be cancellable", NegateLogic=true)] [.<.CancellationToken>("CanBeCanceled", ExpectationMessage="be cancellable")] @@ -900,11 +904,11 @@ namespace .Conditions [.(ExpectationMessage="to not be an empty GUID")] public static bool IsNotEmptyGuid(this value) { } } - public class HasDistinctItemsAssertion : . - where TValue : .IEnumerable + public class HasDistinctItemsAssertion : . + where TCollection : . { - public HasDistinctItemsAssertion(. context) { } - protected override .<.> CheckAsync(. metadata) { } + public HasDistinctItemsAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } public class HasMessageContainingAssertion : . @@ -988,6 +992,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsDefault")] + public class IsDefaultReferenceAssertion : . + where TValue : class + { + public IsDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsEquatableOrEqualTo")] public class IsEquatableOrEqualToAssertion : . { @@ -1032,6 +1044,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsNotDefault")] + public class IsNotDefaultReferenceAssertion : . + where TValue : class + { + public IsNotDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsNotIn")] public class IsNotInAssertion : . { @@ -1308,6 +1328,7 @@ namespace .Conditions } [.("IsNullOrEmpty", CustomName="IsNotNullOrEmpty", ExpectationMessage="be null or empty", NegateLogic=true)] [.("IsNullOrEmpty", ExpectationMessage="be null or empty")] + [.("IsNullOrWhiteSpace", CustomName="IsNotNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace", NegateLogic=true)] [.("IsNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace")] public static class StringStaticMethodAssertions { } public class StructuralEquivalencyAssertion : . @@ -1777,8 +1798,6 @@ namespace .Extensions public static ..DoesNotHaveSameValueAsAssertion DoesNotHaveSameValueAs(this . source, otherEnumValue, [.("otherEnumValue")] string? expression = null) where TEnum : struct, { } public static . EqualTo(this . source, TValue? expected, [.("expected")] string? expression = null) { } - public static . HasDistinctItems(this . source) - where TValue : .IEnumerable { } public static ..HasFlagAssertion HasFlag(this . source, TEnum expectedFlag, [.("expectedFlag")] string? expression = null) where TEnum : struct, { } public static ..LengthWrapper HasLength(this . source) { } @@ -1902,7 +1921,9 @@ namespace .Extensions public static class BooleanAssertionExtensions { public static ._IsFalse_Assertion IsFalse(this . source) { } + public static ._IsFalse_Assertion IsFalse(this . source) { } public static ._IsTrue_Assertion IsTrue(this . source) { } + public static ._IsTrue_Assertion IsTrue(this . source) { } } public static class CancellationTokenAssertionExtensions { @@ -2952,6 +2973,11 @@ namespace .Extensions public static . IsDefault(this . source) where TValue : struct { } } + public static class IsDefaultReferenceAssertionExtensions + { + public static . IsDefault(this . source) + where TValue : class { } + } public static class IsEquatableOrEqualToAssertionExtensions { public static . IsEquatableOrEqualTo(this . source, TValue expected, [.("expected")] string? expectedExpression = null) { } @@ -2980,6 +3006,11 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : struct { } } + public static class IsNotDefaultReferenceAssertionExtensions + { + public static . IsNotDefault(this . source) + where TValue : class { } + } public static class IsNotInAssertionExtensions { public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } @@ -3039,6 +3070,18 @@ namespace .Extensions { public static . IsNull(this . source) { } } + public sealed class NullableBool_IsFalse_Assertion : . + { + public NullableBool_IsFalse_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class NullableBool_IsTrue_Assertion : . + { + public NullableBool_IsTrue_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class NullableEquatableAssertionExtensions { public static . IsEquatableTo(this . source, TExpected expected, [.("expected")] string? expectedExpression = null) @@ -3256,6 +3299,7 @@ namespace .Extensions public static class StringStaticMethodAssertions { public static . IsNotNullOrEmpty(this . source) { } + public static . IsNotNullOrWhiteSpace(this . source) { } public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } @@ -3837,6 +3881,7 @@ namespace .Sources protected override string GetExpectation() { } public ..CountWrapper HasCount() { } public . HasCount(int expectedCount, [.("expectedCount")] string? expression = null) { } + public . HasDistinctItems() { } public . HasSingleItem() { } public . IsEmpty() { } public . IsInDescendingOrder() { } diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt index 6f0410a106..877a9f6456 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt @@ -318,8 +318,12 @@ namespace .Conditions { [.(ExpectationMessage="to be false")] public static bool IsFalse(this bool value) { } + [.(ExpectationMessage="to be false")] + public static bool IsFalse(this bool? value) { } [.(ExpectationMessage="to be true")] public static bool IsTrue(this bool value) { } + [.(ExpectationMessage="to be true")] + public static bool IsTrue(this bool? value) { } } [.<.CancellationToken>("CanBeCanceled", CustomName="CannotBeCanceled", ExpectationMessage="be cancellable", NegateLogic=true)] [.<.CancellationToken>("CanBeCanceled", ExpectationMessage="be cancellable")] @@ -856,11 +860,11 @@ namespace .Conditions [.(ExpectationMessage="to not be an empty GUID")] public static bool IsNotEmptyGuid(this value) { } } - public class HasDistinctItemsAssertion : . - where TValue : .IEnumerable + public class HasDistinctItemsAssertion : . + where TCollection : . { - public HasDistinctItemsAssertion(. context) { } - protected override .<.> CheckAsync(. metadata) { } + public HasDistinctItemsAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } public class HasMessageContainingAssertion : . @@ -941,6 +945,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsDefault")] + public class IsDefaultReferenceAssertion : . + where TValue : class + { + public IsDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsEquatableOrEqualTo")] public class IsEquatableOrEqualToAssertion : . { @@ -982,6 +994,14 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + [.("IsNotDefault")] + public class IsNotDefaultReferenceAssertion : . + where TValue : class + { + public IsNotDefaultReferenceAssertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } [.("IsNotIn")] public class IsNotInAssertion : . { @@ -1242,6 +1262,7 @@ namespace .Conditions } [.("IsNullOrEmpty", CustomName="IsNotNullOrEmpty", ExpectationMessage="be null or empty", NegateLogic=true)] [.("IsNullOrEmpty", ExpectationMessage="be null or empty")] + [.("IsNullOrWhiteSpace", CustomName="IsNotNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace", NegateLogic=true)] [.("IsNullOrWhiteSpace", ExpectationMessage="be null, empty, or whitespace")] public static class StringStaticMethodAssertions { } public class StructuralEquivalencyAssertion : . @@ -1664,8 +1685,6 @@ namespace .Extensions public static ..DoesNotHaveSameValueAsAssertion DoesNotHaveSameValueAs(this . source, otherEnumValue, [.("otherEnumValue")] string? expression = null) where TEnum : struct, { } public static . EqualTo(this . source, TValue? expected, [.("expected")] string? expression = null) { } - public static . HasDistinctItems(this . source) - where TValue : .IEnumerable { } public static ..HasFlagAssertion HasFlag(this . source, TEnum expectedFlag, [.("expectedFlag")] string? expression = null) where TEnum : struct, { } public static ..LengthWrapper HasLength(this . source) { } @@ -1781,7 +1800,9 @@ namespace .Extensions public static class BooleanAssertionExtensions { public static ._IsFalse_Assertion IsFalse(this . source) { } + public static ._IsFalse_Assertion IsFalse(this . source) { } public static ._IsTrue_Assertion IsTrue(this . source) { } + public static ._IsTrue_Assertion IsTrue(this . source) { } } public static class CancellationTokenAssertionExtensions { @@ -2735,6 +2756,11 @@ namespace .Extensions public static . IsDefault(this . source) where TValue : struct { } } + public static class IsDefaultReferenceAssertionExtensions + { + public static . IsDefault(this . source) + where TValue : class { } + } public static class IsEquatableOrEqualToAssertionExtensions { public static . IsEquatableOrEqualTo(this . source, TValue expected, [.("expected")] string? expectedExpression = null) { } @@ -2759,6 +2785,11 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : struct { } } + public static class IsNotDefaultReferenceAssertionExtensions + { + public static . IsNotDefault(this . source) + where TValue : class { } + } public static class IsNotInAssertionExtensions { public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } @@ -2811,6 +2842,18 @@ namespace .Extensions { public static . IsNull(this . source) { } } + public sealed class NullableBool_IsFalse_Assertion : . + { + public NullableBool_IsFalse_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class NullableBool_IsTrue_Assertion : . + { + public NullableBool_IsTrue_Assertion(. context) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class NullableEquatableAssertionExtensions { public static . IsEquatableTo(this . source, TExpected expected, [.("expected")] string? expectedExpression = null) @@ -2996,6 +3039,7 @@ namespace .Extensions public static class StringStaticMethodAssertions { public static . IsNotNullOrEmpty(this . source) { } + public static . IsNotNullOrWhiteSpace(this . source) { } public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } @@ -3494,6 +3538,7 @@ namespace .Sources protected override string GetExpectation() { } public ..CountWrapper HasCount() { } public . HasCount(int expectedCount, [.("expectedCount")] string? expression = null) { } + public . HasDistinctItems() { } public . HasSingleItem() { } public . IsEmpty() { } public . IsInDescendingOrder() { }