Add Xunit.Assert extension methods for comparison and null/empty assertions#86
Conversation
…h tests, docs, and demo Co-authored-by: Burgyn <5930822+Burgyn@users.noreply.github.com>
|
We are using arguments od GreaterThan(value, limit[, epsilon])should be GreaterThan(limit, value[, epsilon])I recommend rewriting original issue #69 and description of this PR to address this. |
Burgyn
left a comment
There was a problem hiding this comment.
Upgrade project to .NET 10 / C# 10 and use new type of extension methods https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14. Then we can use this extension as we use standard XUnit assertion Assert.GreaterThan (...)
namespace Xunit;
public static class AssertExtensions
{
extension(Assert)
{
public static void GreaterThan<T>(T limit, T value) where T : IComparable<T>
{
if (value.CompareTo(limit) <= 0)
{
Fail($"Expected value to be greater than {limit}, but found {value}.");
}
}
}
}|
@copilot merge master to this branch and fix comments. |
…er (limit first, value second) Co-authored-by: Burgyn <5930822+Burgyn@users.noreply.github.com>
Fixed in 9e1f92b. All comparison methods now follow the xUnit convention: first argument is
Done in 9e1f92b. Upgraded both
Done in 9e1f92b. Merged master (which had argument-order fixes for existing tests), upgraded to .NET 10 / C# 14, and implemented the extension type approach and argument order fix per the other comments. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Run dotnet build --configuration Release --no-restore -warnaserror
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(14,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(15,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(30,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(38,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(39,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(58,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
TeaPie -> /home/runner/work/TeaPie/TeaPie/src/TeaPie/bin/Release/net10.0/TeaPie.dll
Successfully created package '/home/runner/work/TeaPie/TeaPie/src/TeaPie/bin/Release/TeaPie.1.5.2.nupkg'.
TeaPie.DotnetTool -> /home/runner/work/TeaPie/TeaPie/src/TeaPie.DotnetTool/bin/Release/net10.0/TeaPie.DotnetTool.dll
Successfully created package '/home/runner/work/TeaPie/TeaPie/src/TeaPie.DotnetTool/bin/Release/TeaPie.Tool.1.5.2.nupkg'.
TeaPie.Tests -> /home/runner/work/TeaPie/TeaPie/tests/TeaPie.Tests/bin/Release/net10.0/TeaPie.Tests.dll
Build FAILED.
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(14,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(15,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(30,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(38,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(39,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
Error: /home/runner/work/TeaPie/TeaPie/src/TeaPie/Pipelines/StepsCollection.cs(58,9): error CA2264: Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264) [/home/runner/work/TeaPie/TeaPie/src/TeaPie/TeaPie.csproj]
0 Warning(s)
6 Error(s)
Time Elapsed 00:00:18.08
Error: Process completed with exit code 1.CI Build failed. Maybe .net version in github action? @copilot fix it. |
…l (not nameof strings) Co-authored-by: Burgyn <5930822+Burgyn@users.noreply.github.com>
Fixed in b9a2b61. The root cause was a pre-existing bug in Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Assert.GreaterThan(limit, value)following xUnit conventionextension(Assert)syntax inXunitnamespaceHeadersResolverShouldCA2264inStepsCollection.cs— all 6ArgumentNullException.ThrowIfNull(nameof(x))calls were passing the string name instead of the variable; replaced withThrowIfNull(x)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.