consolidation of some of the modules, localization fixes, product advisories work, qa work

This commit is contained in:
master
2026-03-05 03:54:22 +02:00
parent 7bafcc3eef
commit 8e1cb9448d
3878 changed files with 72600 additions and 46861 deletions

View File

@@ -1,5 +1,6 @@
using System.Text;
using System.Text.Json;
using System.Runtime.CompilerServices;
using Xunit;
namespace StellaOps.TestKit.Assertions;
@@ -29,15 +30,53 @@ public static class SnapshotAssert
private static readonly bool UpdateSnapshotsMode =
global::System.Environment.GetEnvironmentVariable("UPDATE_SNAPSHOTS") == "1";
/// <summary>
/// Resolves the default snapshot directory for a caller.
/// </summary>
/// <remarks>
/// If the caller source file lives inside a <c>Snapshots</c> directory, that directory is used so
/// snapshots stay source-controlled and deterministic across environments.
/// Otherwise the legacy runtime path (<c>current working directory/Snapshots</c>) is used.
/// </remarks>
public static string ResolveDefaultSnapshotsDirectory([CallerFilePath] string callerFilePath = "")
{
if (!string.IsNullOrWhiteSpace(callerFilePath))
{
var callerDirectory = Path.GetDirectoryName(callerFilePath);
if (!string.IsNullOrWhiteSpace(callerDirectory))
{
if (string.Equals(
Path.GetFileName(callerDirectory),
"Snapshots",
StringComparison.OrdinalIgnoreCase))
{
return callerDirectory;
}
var siblingSnapshots = Path.Combine(callerDirectory, "Snapshots");
if (Directory.Exists(siblingSnapshots))
{
return siblingSnapshots;
}
}
}
return Path.Combine(Directory.GetCurrentDirectory(), "Snapshots");
}
/// <summary>
/// Asserts that the value matches the stored snapshot. If UPDATE_SNAPSHOTS=1, updates the snapshot.
/// </summary>
/// <param name="value">The value to snapshot (will be JSON-serialized).</param>
/// <param name="snapshotName">The snapshot name (filename without extension).</param>
/// <param name="snapshotsDirectory">Optional directory for snapshots (default: "Snapshots" in test project).</param>
public static void MatchesSnapshot<T>(T value, string snapshotName, string? snapshotsDirectory = null)
public static void MatchesSnapshot<T>(
T value,
string snapshotName,
string? snapshotsDirectory = null,
[CallerFilePath] string callerFilePath = "")
{
snapshotsDirectory ??= Path.Combine(Directory.GetCurrentDirectory(), "Snapshots");
snapshotsDirectory ??= ResolveDefaultSnapshotsDirectory(callerFilePath);
Directory.CreateDirectory(snapshotsDirectory);
string snapshotPath = Path.Combine(snapshotsDirectory, $"{snapshotName}.json");
@@ -69,9 +108,13 @@ public static class SnapshotAssert
/// <summary>
/// Asserts that the text matches the stored snapshot.
/// </summary>
public static void MatchesTextSnapshot(string value, string snapshotName, string? snapshotsDirectory = null)
public static void MatchesTextSnapshot(
string value,
string snapshotName,
string? snapshotsDirectory = null,
[CallerFilePath] string callerFilePath = "")
{
snapshotsDirectory ??= Path.Combine(Directory.GetCurrentDirectory(), "Snapshots");
snapshotsDirectory ??= ResolveDefaultSnapshotsDirectory(callerFilePath);
Directory.CreateDirectory(snapshotsDirectory);
string snapshotPath = Path.Combine(snapshotsDirectory, $"{snapshotName}.txt");
@@ -92,9 +135,13 @@ public static class SnapshotAssert
/// <summary>
/// Asserts that binary data matches the stored snapshot.
/// </summary>
public static void MatchesBinarySnapshot(byte[] value, string snapshotName, string? snapshotsDirectory = null)
public static void MatchesBinarySnapshot(
byte[] value,
string snapshotName,
string? snapshotsDirectory = null,
[CallerFilePath] string callerFilePath = "")
{
snapshotsDirectory ??= Path.Combine(Directory.GetCurrentDirectory(), "Snapshots");
snapshotsDirectory ??= ResolveDefaultSnapshotsDirectory(callerFilePath);
Directory.CreateDirectory(snapshotsDirectory);
string snapshotPath = Path.Combine(snapshotsDirectory, $"{snapshotName}.bin");