save progress
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
// <copyright file="Models.cs" company="StellaOps">
|
||||
// Copyright (c) StellaOps. Licensed under AGPL-3.0-or-later.
|
||||
// </copyright>
|
||||
// Sprint: SPRINT_20260105_002_005_TEST_cross_cutting
|
||||
// Task: CCUT-006, CCUT-007
|
||||
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace StellaOps.Testing.SchemaEvolution;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a schema version.
|
||||
/// </summary>
|
||||
/// <param name="VersionId">Version identifier (e.g., "v2024.11", "v2024.12").</param>
|
||||
/// <param name="MigrationId">Migration identifier if applicable.</param>
|
||||
/// <param name="AppliedAt">When this version was applied.</param>
|
||||
public sealed record SchemaVersion(
|
||||
string VersionId,
|
||||
string? MigrationId,
|
||||
DateTimeOffset AppliedAt);
|
||||
|
||||
/// <summary>
|
||||
/// Result of schema compatibility test.
|
||||
/// </summary>
|
||||
/// <param name="IsCompatible">Whether the test passed.</param>
|
||||
/// <param name="BaselineVersion">Schema version used as baseline.</param>
|
||||
/// <param name="TargetVersion">Target schema version tested against.</param>
|
||||
/// <param name="TestedOperation">Type of operation tested.</param>
|
||||
/// <param name="ErrorMessage">Error message if not compatible.</param>
|
||||
/// <param name="Exception">Exception if one occurred.</param>
|
||||
public sealed record SchemaCompatibilityResult(
|
||||
bool IsCompatible,
|
||||
string BaselineVersion,
|
||||
string TargetVersion,
|
||||
SchemaOperationType TestedOperation,
|
||||
string? ErrorMessage = null,
|
||||
Exception? Exception = null);
|
||||
|
||||
/// <summary>
|
||||
/// Type of schema operation tested.
|
||||
/// </summary>
|
||||
public enum SchemaOperationType
|
||||
{
|
||||
/// <summary>
|
||||
/// Read operation (SELECT).
|
||||
/// </summary>
|
||||
Read,
|
||||
|
||||
/// <summary>
|
||||
/// Write operation (INSERT/UPDATE).
|
||||
/// </summary>
|
||||
Write,
|
||||
|
||||
/// <summary>
|
||||
/// Delete operation (DELETE).
|
||||
/// </summary>
|
||||
Delete,
|
||||
|
||||
/// <summary>
|
||||
/// Migration forward (upgrade).
|
||||
/// </summary>
|
||||
MigrationUp,
|
||||
|
||||
/// <summary>
|
||||
/// Migration rollback (downgrade).
|
||||
/// </summary>
|
||||
MigrationDown
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configuration for schema evolution tests.
|
||||
/// </summary>
|
||||
/// <param name="SupportedVersions">Versions to test compatibility with.</param>
|
||||
/// <param name="CurrentVersion">Current schema version.</param>
|
||||
/// <param name="BackwardCompatibilityVersionCount">Number of previous versions to test backward compatibility.</param>
|
||||
/// <param name="ForwardCompatibilityVersionCount">Number of future versions to test forward compatibility.</param>
|
||||
/// <param name="TimeoutPerTest">Timeout per individual test.</param>
|
||||
public sealed record SchemaEvolutionConfig(
|
||||
ImmutableArray<string> SupportedVersions,
|
||||
string CurrentVersion,
|
||||
int BackwardCompatibilityVersionCount = 2,
|
||||
int ForwardCompatibilityVersionCount = 1,
|
||||
TimeSpan TimeoutPerTest = default)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the timeout per test.
|
||||
/// </summary>
|
||||
public TimeSpan TimeoutPerTest { get; init; } =
|
||||
TimeoutPerTest == default ? TimeSpan.FromMinutes(5) : TimeoutPerTest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Information about a database migration.
|
||||
/// </summary>
|
||||
/// <param name="MigrationId">Unique migration identifier.</param>
|
||||
/// <param name="Version">Version this migration belongs to.</param>
|
||||
/// <param name="Description">Human-readable description.</param>
|
||||
/// <param name="HasUpScript">Whether up migration script exists.</param>
|
||||
/// <param name="HasDownScript">Whether down migration script exists.</param>
|
||||
/// <param name="AppliedAt">When the migration was applied.</param>
|
||||
public sealed record MigrationInfo(
|
||||
string MigrationId,
|
||||
string Version,
|
||||
string Description,
|
||||
bool HasUpScript,
|
||||
bool HasDownScript,
|
||||
DateTimeOffset? AppliedAt);
|
||||
|
||||
/// <summary>
|
||||
/// Result of testing migration rollback.
|
||||
/// </summary>
|
||||
/// <param name="Migration">Migration that was tested.</param>
|
||||
/// <param name="Success">Whether rollback succeeded.</param>
|
||||
/// <param name="DurationMs">Duration of rollback in milliseconds.</param>
|
||||
/// <param name="ErrorMessage">Error message if rollback failed.</param>
|
||||
public sealed record MigrationRollbackResult(
|
||||
MigrationInfo Migration,
|
||||
bool Success,
|
||||
long DurationMs,
|
||||
string? ErrorMessage);
|
||||
|
||||
/// <summary>
|
||||
/// Test data seeding result.
|
||||
/// </summary>
|
||||
/// <param name="SchemaVersion">Schema version data was seeded for.</param>
|
||||
/// <param name="RecordsSeeded">Number of records seeded.</param>
|
||||
/// <param name="DurationMs">Duration of seeding in milliseconds.</param>
|
||||
public sealed record SeedDataResult(
|
||||
string SchemaVersion,
|
||||
int RecordsSeeded,
|
||||
long DurationMs);
|
||||
|
||||
/// <summary>
|
||||
/// Report of schema evolution test suite.
|
||||
/// </summary>
|
||||
/// <param name="TotalTests">Total number of tests executed.</param>
|
||||
/// <param name="PassedTests">Number of passed tests.</param>
|
||||
/// <param name="FailedTests">Number of failed tests.</param>
|
||||
/// <param name="SkippedTests">Number of skipped tests.</param>
|
||||
/// <param name="Results">Individual test results.</param>
|
||||
/// <param name="TotalDurationMs">Total duration in milliseconds.</param>
|
||||
public sealed record SchemaEvolutionReport(
|
||||
int TotalTests,
|
||||
int PassedTests,
|
||||
int FailedTests,
|
||||
int SkippedTests,
|
||||
ImmutableArray<SchemaCompatibilityResult> Results,
|
||||
long TotalDurationMs)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether all tests passed.
|
||||
/// </summary>
|
||||
public bool IsSuccess => FailedTests == 0;
|
||||
}
|
||||
Reference in New Issue
Block a user