diff --git a/TUnit.CI.slnx b/TUnit.CI.slnx
index dc649a60890..10f93a39731 100644
--- a/TUnit.CI.slnx
+++ b/TUnit.CI.slnx
@@ -87,6 +87,7 @@
+
diff --git a/TUnit.Dev.slnx b/TUnit.Dev.slnx
index 127bb8d1521..d107eb81076 100644
--- a/TUnit.Dev.slnx
+++ b/TUnit.Dev.slnx
@@ -7,6 +7,7 @@
+
@@ -18,6 +19,7 @@
+
@@ -28,6 +30,7 @@
+
@@ -44,6 +47,7 @@
+
@@ -54,8 +58,13 @@
+
+
+
+
+
@@ -63,12 +72,16 @@
+
+
+
+
diff --git a/tests/SharedTestHelpers/DotNetCli.cs b/tests/SharedTestHelpers/DotNetCli.cs
new file mode 100644
index 00000000000..c1b63e0878f
--- /dev/null
+++ b/tests/SharedTestHelpers/DotNetCli.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace TUnit.Tests.Shared;
+
+///
+/// Resolves the dotnet executable used to start child dotnet build/dotnet run processes.
+///
+///
+/// A bare dotnet resolves through PATH, which an IDE does not necessarily share with the
+/// installation it builds and runs tests with (on macOS, apps started from the Dock or Finder get a different
+/// PATH than a terminal). That dotnet can lack an SDK satisfying global.json and exit with
+/// 155 (SdkResolveFailure). Prefer the installation that is running the current test process, as long as it
+/// resolves an SDK for this repository: a runtime-only installation, or one whose SDKs don't satisfy
+/// global.json, cannot run dotnet build here, so PATH is the better bet there.
+///
+internal static class DotNetCli
+{
+ // Resolved on first use rather than in the type initializer, so an unexpected failure surfaces as itself
+ // instead of a TypeInitializationException that also breaks every later use of the type
+ private static readonly Lazy ResolvedPath = new(Resolve);
+
+ /// The dotnet executable to start child processes with: a full path, or dotnet to use PATH.
+ public static string Path => ResolvedPath.Value;
+
+ ///
+ /// Prefers DOTNET_HOST_PATH, then the muxer of the installation running this process when it resolves an
+ /// SDK for this repository, and otherwise falls back to dotnet on PATH.
+ ///
+ private static string Resolve()
+ {
+ // Set by the .NET CLI for processes it starts (e.g. under `dotnet test`), so it already resolved an SDK.
+ var hostPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH");
+ if (!string.IsNullOrEmpty(hostPath) && File.Exists(hostPath))
+ {
+ return hostPath;
+ }
+
+ // /shared/Microsoft.NETCore.App// -> /dotnet
+ var runtimeDirectory = RuntimeEnvironment.GetRuntimeDirectory();
+ var root = System.IO.Path.GetFullPath(System.IO.Path.Combine(runtimeDirectory, "..", "..", ".."));
+ var muxer = System.IO.Path.Combine(root, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dotnet.exe" : "dotnet");
+
+ return File.Exists(muxer) && ResolvesSdk(muxer) ? muxer : "dotnet";
+ }
+
+ ///
+ /// Whether resolves an SDK from the test assembly's directory, which lies inside the
+ /// repository: dotnet --version applies global.json the same way the child builds do and fails, with
+ /// 155, exactly when they would.
+ ///
+ private static bool ResolvesSdk(string muxer)
+ {
+ try
+ {
+ using var process = Process.Start(new ProcessStartInfo(muxer, "--version")
+ {
+ WorkingDirectory = AppContext.BaseDirectory,
+ UseShellExecute = false,
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ CreateNoWindow = true,
+ });
+
+ if (process is null)
+ {
+ return false;
+ }
+
+ // Drain and discard both streams so neither can fill up and block the process
+ process.OutputDataReceived += static (_, _) => { };
+ process.ErrorDataReceived += static (_, _) => { };
+ process.BeginOutputReadLine();
+ process.BeginErrorReadLine();
+
+ if (!process.WaitForExit(30_000))
+ {
+ process.Kill(entireProcessTree: true);
+ return false;
+ }
+
+ return process.ExitCode == 0;
+ }
+ catch (Exception exception) when (exception is InvalidOperationException or System.ComponentModel.Win32Exception or IOException)
+ {
+ return false;
+ }
+ }
+}
diff --git a/tests/SharedTestHelpers/TestHostReferences.cs b/tests/SharedTestHelpers/TestHostReferences.cs
new file mode 100644
index 00000000000..186a8d30bf0
--- /dev/null
+++ b/tests/SharedTestHelpers/TestHostReferences.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using Microsoft.CodeAnalysis;
+
+namespace TUnit.Tests.Shared;
+
+///
+/// Paths of the assemblies that in-memory test compilations (generator and analyzer tests) reference.
+///
+///
+/// AppDomain.CurrentDomain.GetAssemblies() only returns what the process has loaded so far, which depends on
+/// how the test host was launched: IDE and dotnet test server-mode hosts load assemblies (e.g. System.Net.*)
+/// that a plain run does not, so types such as System.Net.HttpStatusCode resolved or not and generator output
+/// differed between launches. On .NET, TRUSTED_PLATFORM_ASSEMBLIES lists the app's whole deployment
+/// (framework plus deps.json) up front. .NET Framework has no such list, so it keeps the loaded assemblies.
+///
+/// Neither source has a defined order (the TPA order differs between Linux and macOS hosts), and generators emit
+/// referenced assemblies in reference order, so the paths are sorted to keep snapshots identical on every host.
+///
+///
+internal static class TestHostReferences
+{
+ /// The assembly paths to reference, sorted by file name and then by path.
+ public static IReadOnlyList AssemblyPaths { get; } = Resolve();
+
+ ///
+ /// Metadata references to , followed by .
+ ///
+ public static List CreateReferences(params Assembly[] additionalAssemblies) =>
+ CreateReferences(static _ => true, additionalAssemblies);
+
+ ///
+ /// Metadata references to the that accepts,
+ /// followed by .
+ ///
+ public static List CreateReferences(Func includeHostAssembly, params Assembly[] additionalAssemblies) =>
+ AssemblyPaths
+ .Where(includeHostAssembly)
+ .Concat(additionalAssemblies.Select(assembly => assembly.Location))
+ .Select(path => MetadataReference.CreateFromFile(path))
+ .ToList();
+
+ ///
+ /// Reads TRUSTED_PLATFORM_ASSEMBLIES on .NET, or the loaded assemblies on .NET Framework, and sorts them.
+ ///
+ private static string[] Resolve()
+ {
+ var paths = AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") is string trustedPlatformAssemblies
+ ? trustedPlatformAssemblies.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries)
+ : AppDomain.CurrentDomain.GetAssemblies()
+ .Where(assembly => !assembly.IsDynamic && !string.IsNullOrWhiteSpace(assembly.Location))
+ .Select(assembly => assembly.Location);
+
+ // Ordinal on purpose: reference order shows up in generator output, so a culture-aware sort, or no sort, would
+ // reorder snapshots between hosts. A snapshot that reorders after a change here is this sort, not the generator.
+ return paths
+ .OrderBy(Path.GetFileName, StringComparer.Ordinal)
+ .ThenBy(path => path, StringComparer.Ordinal)
+ .ToArray();
+ }
+}
diff --git a/tests/Snapshots/TUnit._.verified/std-streams/stderr.txt b/tests/Snapshots/TUnit._.verified/std-streams/stderr.txt
deleted file mode 100644
index 5f282702bb0..00000000000
--- a/tests/Snapshots/TUnit._.verified/std-streams/stderr.txt
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/tests/Snapshots/TUnit._.verified/std-streams/stdout.txt b/tests/Snapshots/TUnit._.verified/std-streams/stdout.txt
deleted file mode 100644
index 5f282702bb0..00000000000
--- a/tests/Snapshots/TUnit._.verified/std-streams/stdout.txt
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/tests/TUnit.Aspire.Tests/TUnit.Aspire.Tests.csproj b/tests/TUnit.Aspire.Tests/TUnit.Aspire.Tests.csproj
index 45563f0c7d1..4fd89e03519 100644
--- a/tests/TUnit.Aspire.Tests/TUnit.Aspire.Tests.csproj
+++ b/tests/TUnit.Aspire.Tests/TUnit.Aspire.Tests.csproj
@@ -1,6 +1,6 @@
-
+
net10.0
@@ -11,17 +11,14 @@
-
-
-
-
-
+
+
diff --git a/tests/TUnit.Assertions.Should.SourceGenerator.Tests/ShouldExtensionGeneratorTests.cs b/tests/TUnit.Assertions.Should.SourceGenerator.Tests/ShouldExtensionGeneratorTests.cs
index 3d51d753678..8d5f666e10f 100644
--- a/tests/TUnit.Assertions.Should.SourceGenerator.Tests/ShouldExtensionGeneratorTests.cs
+++ b/tests/TUnit.Assertions.Should.SourceGenerator.Tests/ShouldExtensionGeneratorTests.cs
@@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using TUnit.Assertions.Core;
+using TUnit.Tests.Shared;
namespace TUnit.Assertions.Should.SourceGenerator.Tests;
@@ -448,7 +449,7 @@ public sealed class OverloadResolutionPriorityAttribute : System.Attribute
var compilation = CSharpCompilation.Create(
assemblyName: "GeneratorTest",
syntaxTrees: inputTrees,
- references: GetReferences(),
+ references: References,
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
var driver = CSharpGeneratorDriver.Create(new ShouldExtensionGenerator());
@@ -471,25 +472,11 @@ await Verify(combined)
return combined;
}
- private static IEnumerable GetReferences()
- {
- // Mirror the loaded assemblies of the test process. Works on both .NET Core
- // (where TRUSTED_PLATFORM_ASSEMBLIES populates this set) and .NET Framework,
- // unlike AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") which returns
- // null on .NET Framework and would leave the in-memory compilation without BCL
- // references — making symbol resolution silently fail in the generator.
- foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
- {
- if (asm.IsDynamic || string.IsNullOrWhiteSpace(asm.Location))
- {
- continue;
- }
- yield return MetadataReference.CreateFromFile(asm.Location);
- }
-
- yield return MetadataReference.CreateFromFile(typeof(Assertion<>).Assembly.Location);
- yield return MetadataReference.CreateFromFile(typeof(TUnit.Assertions.Should.Core.IShouldSource).Assembly.Location);
- }
+ // Built once: every test compiles against the same references, and each one reads its file from disk
+ private static readonly List References =
+ TestHostReferences.CreateReferences(
+ typeof(Assertion<>).Assembly,
+ typeof(TUnit.Assertions.Should.Core.IShouldSource).Assembly);
private static int CountOccurrences(string value, string search)
{
diff --git a/tests/TUnit.Assertions.Should.SourceGenerator.Tests/TUnit.Assertions.Should.SourceGenerator.Tests.csproj b/tests/TUnit.Assertions.Should.SourceGenerator.Tests/TUnit.Assertions.Should.SourceGenerator.Tests.csproj
index adf9e190815..4da6334b299 100644
--- a/tests/TUnit.Assertions.Should.SourceGenerator.Tests/TUnit.Assertions.Should.SourceGenerator.Tests.csproj
+++ b/tests/TUnit.Assertions.Should.SourceGenerator.Tests/TUnit.Assertions.Should.SourceGenerator.Tests.csproj
@@ -17,6 +17,10 @@
$(NoWarn);MSB3277
+
+
+
+
diff --git a/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet10_0.verified.txt b/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet10_0.verified.txt
index 9a654aa3ff7..0229802d5bd 100644
--- a/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet10_0.verified.txt
+++ b/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet10_0.verified.txt
@@ -14,16 +14,16 @@ namespace TUnit.Assertions.Extensions;
///
/// Generated assertion for IsSuccess
///
-public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
+public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsSuccess_Assertion(AssertionContext context)
+ public HttpStatusCode_IsSuccess_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -33,12 +33,7 @@ public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion= 200 and < 300;
+ var result = (int)value is >= 200 and < 300;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -53,16 +48,16 @@ public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
/// Generated assertion for IsNotSuccess
///
-public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
+public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsNotSuccess_Assertion(AssertionContext context)
+ public HttpStatusCode_IsNotSuccess_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -72,12 +67,7 @@ public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion= 300;
+ var result = (int)value is < 200 or >= 300;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -92,16 +82,16 @@ public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
/// Generated assertion for IsClientError
///
-public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
+public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsClientError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsClientError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -111,12 +101,7 @@ public sealed class HttpStatusCode_IsClientError_Assertion : Assertion= 400 and < 500;
+ var result = (int)value is >= 400 and < 500;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -131,16 +116,16 @@ public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
/// Generated assertion for IsServerError
///
-public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
+public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsServerError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsServerError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -150,12 +135,7 @@ public sealed class HttpStatusCode_IsServerError_Assertion : Assertion= 500 and < 600;
+ var result = (int)value is >= 500 and < 600;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -170,16 +150,16 @@ public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
/// Generated assertion for IsRedirection
///
-public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
+public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsRedirection_Assertion(AssertionContext context)
+ public HttpStatusCode_IsRedirection_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -189,12 +169,7 @@ public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion= 300 and < 400;
+ var result = (int)value is >= 300 and < 400;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -209,16 +184,16 @@ public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
/// Generated assertion for IsInformational
///
-public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
+public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsInformational_Assertion(AssertionContext context)
+ public HttpStatusCode_IsInformational_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -228,12 +203,7 @@ public sealed class HttpStatusCode_IsInformational_Assertion : Assertion= 100 and < 200;
+ var result = (int)value is >= 100 and < 200;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -248,16 +218,16 @@ public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
/// Generated assertion for IsError
///
-public sealed class HttpStatusCode_IsError_Assertion : Assertion
+public sealed class HttpStatusCode_IsError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -267,12 +237,7 @@ public sealed class HttpStatusCode_IsError_Assertion : Assertion
return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().FullName}"));
}
- if (value is null)
- {
- return Task.FromResult(AssertionResult.Failed("Actual value is null"));
- }
-
- var result = (int)value! is >= 400 and < 600;
+ var result = (int)value is >= 400 and < 600;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -289,7 +254,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsSuccess
///
- public static HttpStatusCode_IsSuccess_Assertion IsSuccess(this IAssertionSource source)
+ public static HttpStatusCode_IsSuccess_Assertion IsSuccess(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsSuccess()");
return new HttpStatusCode_IsSuccess_Assertion(source.Context);
@@ -298,7 +263,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsNotSuccess
///
- public static HttpStatusCode_IsNotSuccess_Assertion IsNotSuccess(this IAssertionSource source)
+ public static HttpStatusCode_IsNotSuccess_Assertion IsNotSuccess(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsNotSuccess()");
return new HttpStatusCode_IsNotSuccess_Assertion(source.Context);
@@ -307,7 +272,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsClientError
///
- public static HttpStatusCode_IsClientError_Assertion IsClientError(this IAssertionSource source)
+ public static HttpStatusCode_IsClientError_Assertion IsClientError(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsClientError()");
return new HttpStatusCode_IsClientError_Assertion(source.Context);
@@ -316,7 +281,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsServerError
///
- public static HttpStatusCode_IsServerError_Assertion IsServerError(this IAssertionSource source)
+ public static HttpStatusCode_IsServerError_Assertion IsServerError(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsServerError()");
return new HttpStatusCode_IsServerError_Assertion(source.Context);
@@ -325,7 +290,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsRedirection
///
- public static HttpStatusCode_IsRedirection_Assertion IsRedirection(this IAssertionSource source)
+ public static HttpStatusCode_IsRedirection_Assertion IsRedirection(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsRedirection()");
return new HttpStatusCode_IsRedirection_Assertion(source.Context);
@@ -334,7 +299,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsInformational
///
- public static HttpStatusCode_IsInformational_Assertion IsInformational(this IAssertionSource source)
+ public static HttpStatusCode_IsInformational_Assertion IsInformational(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsInformational()");
return new HttpStatusCode_IsInformational_Assertion(source.Context);
@@ -343,7 +308,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsError
///
- public static HttpStatusCode_IsError_Assertion IsError(this IAssertionSource source)
+ public static HttpStatusCode_IsError_Assertion IsError(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsError()");
return new HttpStatusCode_IsError_Assertion(source.Context);
diff --git a/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet8_0.verified.txt b/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet8_0.verified.txt
index 9a654aa3ff7..0229802d5bd 100644
--- a/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet8_0.verified.txt
+++ b/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet8_0.verified.txt
@@ -14,16 +14,16 @@ namespace TUnit.Assertions.Extensions;
///
/// Generated assertion for IsSuccess
///
-public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
+public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsSuccess_Assertion(AssertionContext context)
+ public HttpStatusCode_IsSuccess_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -33,12 +33,7 @@ public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion= 200 and < 300;
+ var result = (int)value is >= 200 and < 300;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -53,16 +48,16 @@ public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
/// Generated assertion for IsNotSuccess
///
-public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
+public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsNotSuccess_Assertion(AssertionContext context)
+ public HttpStatusCode_IsNotSuccess_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -72,12 +67,7 @@ public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion= 300;
+ var result = (int)value is < 200 or >= 300;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -92,16 +82,16 @@ public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
/// Generated assertion for IsClientError
///
-public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
+public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsClientError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsClientError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -111,12 +101,7 @@ public sealed class HttpStatusCode_IsClientError_Assertion : Assertion= 400 and < 500;
+ var result = (int)value is >= 400 and < 500;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -131,16 +116,16 @@ public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
/// Generated assertion for IsServerError
///
-public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
+public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsServerError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsServerError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -150,12 +135,7 @@ public sealed class HttpStatusCode_IsServerError_Assertion : Assertion= 500 and < 600;
+ var result = (int)value is >= 500 and < 600;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -170,16 +150,16 @@ public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
/// Generated assertion for IsRedirection
///
-public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
+public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsRedirection_Assertion(AssertionContext context)
+ public HttpStatusCode_IsRedirection_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -189,12 +169,7 @@ public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion= 300 and < 400;
+ var result = (int)value is >= 300 and < 400;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -209,16 +184,16 @@ public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
/// Generated assertion for IsInformational
///
-public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
+public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsInformational_Assertion(AssertionContext context)
+ public HttpStatusCode_IsInformational_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -228,12 +203,7 @@ public sealed class HttpStatusCode_IsInformational_Assertion : Assertion= 100 and < 200;
+ var result = (int)value is >= 100 and < 200;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -248,16 +218,16 @@ public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
/// Generated assertion for IsError
///
-public sealed class HttpStatusCode_IsError_Assertion : Assertion
+public sealed class HttpStatusCode_IsError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -267,12 +237,7 @@ public sealed class HttpStatusCode_IsError_Assertion : Assertion
return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().FullName}"));
}
- if (value is null)
- {
- return Task.FromResult(AssertionResult.Failed("Actual value is null"));
- }
-
- var result = (int)value! is >= 400 and < 600;
+ var result = (int)value is >= 400 and < 600;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -289,7 +254,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsSuccess
///
- public static HttpStatusCode_IsSuccess_Assertion IsSuccess(this IAssertionSource source)
+ public static HttpStatusCode_IsSuccess_Assertion IsSuccess(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsSuccess()");
return new HttpStatusCode_IsSuccess_Assertion(source.Context);
@@ -298,7 +263,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsNotSuccess
///
- public static HttpStatusCode_IsNotSuccess_Assertion IsNotSuccess(this IAssertionSource source)
+ public static HttpStatusCode_IsNotSuccess_Assertion IsNotSuccess(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsNotSuccess()");
return new HttpStatusCode_IsNotSuccess_Assertion(source.Context);
@@ -307,7 +272,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsClientError
///
- public static HttpStatusCode_IsClientError_Assertion IsClientError(this IAssertionSource source)
+ public static HttpStatusCode_IsClientError_Assertion IsClientError(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsClientError()");
return new HttpStatusCode_IsClientError_Assertion(source.Context);
@@ -316,7 +281,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsServerError
///
- public static HttpStatusCode_IsServerError_Assertion IsServerError(this IAssertionSource source)
+ public static HttpStatusCode_IsServerError_Assertion IsServerError(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsServerError()");
return new HttpStatusCode_IsServerError_Assertion(source.Context);
@@ -325,7 +290,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsRedirection
///
- public static HttpStatusCode_IsRedirection_Assertion IsRedirection(this IAssertionSource source)
+ public static HttpStatusCode_IsRedirection_Assertion IsRedirection(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsRedirection()");
return new HttpStatusCode_IsRedirection_Assertion(source.Context);
@@ -334,7 +299,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsInformational
///
- public static HttpStatusCode_IsInformational_Assertion IsInformational(this IAssertionSource source)
+ public static HttpStatusCode_IsInformational_Assertion IsInformational(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsInformational()");
return new HttpStatusCode_IsInformational_Assertion(source.Context);
@@ -343,7 +308,7 @@ public static partial class HttpStatusCodeAssertionExtensions
///
/// Generated extension method for IsError
///
- public static HttpStatusCode_IsError_Assertion IsError(this IAssertionSource source)
+ public static HttpStatusCode_IsError_Assertion IsError(this IAssertionSource source)
{
source.Context.ExpressionBuilder.Append(".IsError()");
return new HttpStatusCode_IsError_Assertion(source.Context);
diff --git a/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet9_0.verified.txt b/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet9_0.verified.txt
index 9a654aa3ff7..0229802d5bd 100644
--- a/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet9_0.verified.txt
+++ b/tests/TUnit.Assertions.SourceGenerator.Tests/HttpStatusCodeAssertionGeneratorTests.GeneratesHttpStatusCodeAssertions.DotNet9_0.verified.txt
@@ -14,16 +14,16 @@ namespace TUnit.Assertions.Extensions;
///
/// Generated assertion for IsSuccess
///
-public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
+public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsSuccess_Assertion(AssertionContext context)
+ public HttpStatusCode_IsSuccess_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -33,12 +33,7 @@ public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion= 200 and < 300;
+ var result = (int)value is >= 200 and < 300;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -53,16 +48,16 @@ public sealed class HttpStatusCode_IsSuccess_Assertion : Assertion
/// Generated assertion for IsNotSuccess
///
-public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
+public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsNotSuccess_Assertion(AssertionContext context)
+ public HttpStatusCode_IsNotSuccess_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -72,12 +67,7 @@ public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion= 300;
+ var result = (int)value is < 200 or >= 300;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -92,16 +82,16 @@ public sealed class HttpStatusCode_IsNotSuccess_Assertion : Assertion
/// Generated assertion for IsClientError
///
-public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
+public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsClientError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsClientError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -111,12 +101,7 @@ public sealed class HttpStatusCode_IsClientError_Assertion : Assertion= 400 and < 500;
+ var result = (int)value is >= 400 and < 500;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -131,16 +116,16 @@ public sealed class HttpStatusCode_IsClientError_Assertion : Assertion
/// Generated assertion for IsServerError
///
-public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
+public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsServerError_Assertion(AssertionContext context)
+ public HttpStatusCode_IsServerError_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -150,12 +135,7 @@ public sealed class HttpStatusCode_IsServerError_Assertion : Assertion= 500 and < 600;
+ var result = (int)value is >= 500 and < 600;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -170,16 +150,16 @@ public sealed class HttpStatusCode_IsServerError_Assertion : Assertion
/// Generated assertion for IsRedirection
///
-public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
+public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsRedirection_Assertion(AssertionContext context)
+ public HttpStatusCode_IsRedirection_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata metadata)
+ protected override Task CheckAsync(EvaluationMetadata metadata)
{
var value = metadata.Value;
var exception = metadata.Exception;
@@ -189,12 +169,7 @@ public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion= 300 and < 400;
+ var result = (int)value is >= 300 and < 400;
return result
? _passedTask
: Task.FromResult(AssertionResult.Failed($"found {value}"));
@@ -209,16 +184,16 @@ public sealed class HttpStatusCode_IsRedirection_Assertion : Assertion
/// Generated assertion for IsInformational
///
-public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
+public sealed class HttpStatusCode_IsInformational_Assertion : Assertion
{
private static readonly Task _passedTask = Task.FromResult(AssertionResult.Passed);
- public HttpStatusCode_IsInformational_Assertion(AssertionContext context)
+ public HttpStatusCode_IsInformational_Assertion(AssertionContext context)
: base(context)
{
}
- protected override Task CheckAsync(EvaluationMetadata