Skip to content

Commit dc06b60

Browse files
authored
feat(assertions): re-add some lost assertions (#3467)
* feat(assertions): re-add some lost assertions * feat(assertions): re-add some lost assertions * feat(assertions): re-add some lost assertions
1 parent b9eb936 commit dc06b60

File tree

53 files changed

+577
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+577
-92
lines changed

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet10_0.verified.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions
1920
/// </summary>
2021
public static DefaultValuesAssertion<TValue> HasDefaultValues<TValue>(this IAssertionSource<TValue> 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)
2122
{
22-
source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})");
23+
source.Context.ExpressionBuilder.Append(".HasDefaultValues("
24+
+ string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")");
2325
return new DefaultValuesAssertion<TValue>(source.Context, boolValue, intValue, stringValue);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet8_0.verified.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions
1920
/// </summary>
2021
public static DefaultValuesAssertion<TValue> HasDefaultValues<TValue>(this IAssertionSource<TValue> 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)
2122
{
22-
source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})");
23+
source.Context.ExpressionBuilder.Append(".HasDefaultValues("
24+
+ string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")");
2325
return new DefaultValuesAssertion<TValue>(source.Context, boolValue, intValue, stringValue);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.DotNet9_0.verified.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions
1920
/// </summary>
2021
public static DefaultValuesAssertion<TValue> HasDefaultValues<TValue>(this IAssertionSource<TValue> 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)
2122
{
22-
source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})");
23+
source.Context.ExpressionBuilder.Append(".HasDefaultValues("
24+
+ string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")");
2325
return new DefaultValuesAssertion<TValue>(source.Context, boolValue, intValue, stringValue);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithDefaultValues.Net4_7.verified.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -19,7 +20,8 @@ public static class DefaultValuesAssertionExtensions
1920
/// </summary>
2021
public static DefaultValuesAssertion<TValue> HasDefaultValues<TValue>(this IAssertionSource<TValue> 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)
2122
{
22-
source.Context.ExpressionBuilder.Append($".HasDefaultValues({boolValueExpression}, {intValueExpression}, {stringValueExpression})");
23+
source.Context.ExpressionBuilder.Append(".HasDefaultValues("
24+
+ string.Join(", ", new[] { boolValueExpression, intValueExpression, stringValueExpression }.Where(e => e != null)) + ")");
2325
return new DefaultValuesAssertion<TValue>(source.Context, boolValue, intValue, stringValue);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet10_0.verified.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions
1718
/// <summary>
1819
/// Extension method for StringComparisonAssertion.
1920
/// </summary>
20-
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
21+
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
2122
{
22-
source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})");
23+
source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison("
24+
+ string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")");
2325
return new StringComparisonAssertion(source.Context, expected, comparison);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet8_0.verified.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions
1718
/// <summary>
1819
/// Extension method for StringComparisonAssertion.
1920
/// </summary>
20-
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
21+
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
2122
{
22-
source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})");
23+
source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison("
24+
+ string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")");
2325
return new StringComparisonAssertion(source.Context, expected, comparison);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.DotNet9_0.verified.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions
1718
/// <summary>
1819
/// Extension method for StringComparisonAssertion.
1920
/// </summary>
20-
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
21+
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
2122
{
22-
source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})");
23+
source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison("
24+
+ string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")");
2325
return new StringComparisonAssertion(source.Context, expected, comparison);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithEnumDefault.Net4_7.verified.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -17,9 +18,10 @@ public static class StringComparisonAssertionExtensions
1718
/// <summary>
1819
/// Extension method for StringComparisonAssertion.
1920
/// </summary>
20-
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = System.StringComparison.4, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
21+
public static StringComparisonAssertion IsEqualToWithComparison(this IAssertionSource<string> source, string expected, System.StringComparison comparison = StringComparison.Ordinal, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, [CallerArgumentExpression(nameof(comparison))] string? comparisonExpression = null)
2122
{
22-
source.Context.ExpressionBuilder.Append($".IsEqualToWithComparison({expectedExpression}, {comparisonExpression})");
23+
source.Context.ExpressionBuilder.Append(".IsEqualToWithComparison("
24+
+ string.Join(", ", new[] { expectedExpression, comparisonExpression }.Where(e => e != null)) + ")");
2325
return new StringComparisonAssertion(source.Context, expected, comparison);
2426
}
2527
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet10_0.verified.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -20,7 +21,8 @@ public static class GreaterThanAssertionExtensions
2021
public static GreaterThanAssertion<TValue> IsGreaterThan<TValue>(this IAssertionSource<TValue> source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null)
2122
where TValue : System.IComparable<TValue>
2223
{
23-
source.Context.ExpressionBuilder.Append($".IsGreaterThan({expectedExpression})");
24+
source.Context.ExpressionBuilder.Append(".IsGreaterThan("
25+
+ string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")");
2426
return new GreaterThanAssertion<TValue>(source.Context, expected);
2527
}
2628
}

TUnit.Assertions.SourceGenerator.Tests/AssertionExtensionGeneratorTests.AssertionWithGenericConstraints.DotNet8_0.verified.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using TUnit.Assertions.Core;
7+
using TUnit.Assertions.Enums;
78
using TUnit.Assertions.Tests.TestData;
89

910
namespace TUnit.Assertions.Extensions;
@@ -20,7 +21,8 @@ public static class GreaterThanAssertionExtensions
2021
public static GreaterThanAssertion<TValue> IsGreaterThan<TValue>(this IAssertionSource<TValue> source, TValue expected, [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null)
2122
where TValue : System.IComparable<TValue>
2223
{
23-
source.Context.ExpressionBuilder.Append($".IsGreaterThan({expectedExpression})");
24+
source.Context.ExpressionBuilder.Append(".IsGreaterThan("
25+
+ string.Join(", ", new[] { expectedExpression }.Where(e => e != null)) + ")");
2426
return new GreaterThanAssertion<TValue>(source.Context, expected);
2527
}
2628
}

0 commit comments

Comments
 (0)