docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
This commit is contained in:
@@ -5,7 +5,7 @@ using ZB.MOM.WW.ScadaBridge.TestSupport;
|
||||
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// WP-33: Local Artifact Storage tests — shared scripts, external systems,
|
||||
/// Local Artifact Storage tests — shared scripts, external systems,
|
||||
/// database connections, notification lists.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
@@ -17,11 +17,14 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
private readonly TestLocalDb _localDb;
|
||||
private SiteStorageService _storage = null!;
|
||||
|
||||
/// <summary>Creates a temporary LocalDb for the tests.</summary>
|
||||
public ArtifactStorageTests()
|
||||
{
|
||||
_localDb = TestLocalDb.CreateTemp("artifact-test");
|
||||
}
|
||||
|
||||
/// <summary>Creates and initializes the storage service under test.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_storage = new SiteStorageService(
|
||||
@@ -30,8 +33,11 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
await _storage.InitializeAsync();
|
||||
}
|
||||
|
||||
/// <summary>Does nothing; there is no asynchronous cleanup.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
/// <summary>Disposes the test database and deletes its files.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// Dispose first — the master connection anchors the WAL, so the sidecars
|
||||
@@ -43,6 +49,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── Shared Script Storage ──
|
||||
|
||||
/// <summary>Verifies that a stored shared script round-trips.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreSharedScript_RoundTrips()
|
||||
{
|
||||
@@ -56,6 +64,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("int", scripts[0].ReturnDefinition);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that storing a shared script with an existing name upserts it.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreSharedScript_Upserts_OnConflict()
|
||||
{
|
||||
@@ -68,6 +78,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("{\"x\":\"int\"}", scripts[0].ParameterDefinitions);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that multiple shared scripts can be stored side by side.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreSharedScript_MultipleScripts()
|
||||
{
|
||||
@@ -79,6 +91,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(3, scripts.Count);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a shared script with null optional fields can be stored.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreSharedScript_NullableFields()
|
||||
{
|
||||
@@ -92,6 +106,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── External System Storage ──
|
||||
|
||||
/// <summary>Verifies that storing an external system does not throw.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreExternalSystem_DoesNotThrow()
|
||||
{
|
||||
@@ -102,6 +118,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
// No exception = success. Query verification would need a Get method.
|
||||
}
|
||||
|
||||
/// <summary>Verifies that storing an external system with an existing name upserts it.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreExternalSystem_Upserts()
|
||||
{
|
||||
@@ -113,6 +131,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── Database Connection Storage ──
|
||||
|
||||
/// <summary>Verifies that storing a database connection does not throw.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreDatabaseConnection_DoesNotThrow()
|
||||
{
|
||||
@@ -120,6 +140,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
"MainDB", "Server=localhost;Database=main", 3, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that storing a database connection with an existing name upserts it.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreDatabaseConnection_Upserts()
|
||||
{
|
||||
@@ -139,6 +161,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
// shared script / DB connection / data connection) stayed orphaned on the site
|
||||
// forever and remained callable from site scripts.
|
||||
|
||||
/// <summary>Verifies that deleting shared scripts except a keep set removes orphans and keeps the present ones.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DeleteSharedScriptsExcept_RemovesOrphans_KeepsPresent()
|
||||
{
|
||||
@@ -153,6 +177,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(["Keep1", "Keep2"], names);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deleting external systems except a keep set removes orphans and keeps the present ones.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DeleteExternalSystemsExcept_RemovesOrphans_KeepsPresent()
|
||||
{
|
||||
@@ -165,6 +191,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(["MES"], await TableNamesAsync("external_systems"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deleting database connections with an empty keep set deletes all of them.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DeleteDatabaseConnectionsExcept_EmptyKeepSet_DeletesAll()
|
||||
{
|
||||
@@ -178,6 +206,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Empty(await TableNamesAsync("database_connections"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deleting data connection definitions except a keep set removes orphans and keeps the present ones.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DeleteDataConnectionDefinitionsExcept_RemovesOrphans_KeepsPresent()
|
||||
{
|
||||
@@ -191,6 +221,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(["PlcA"], names);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deleting with no orphans returns an empty result and is idempotent.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DeleteRowsExcept_NoOrphans_ReturnsEmpty_AndIsIdempotent()
|
||||
{
|
||||
@@ -213,10 +245,10 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
return names;
|
||||
}
|
||||
|
||||
// ── DeploymentManager-025 / SiteRuntime-031: central-only notif/SMTP purge ──
|
||||
// ── Central-only notif/SMTP purge ──
|
||||
//
|
||||
// Notification config is central-only. The site-side write paths and
|
||||
// SiteNotificationRepository were removed 2026-07-10 (arch-review 08 §1.3/#23);
|
||||
// SiteNotificationRepository were removed 2026-07-10 (arch-review 08 §1.3);
|
||||
// PurgeCentralOnlyNotificationConfigAsync is retained as the security cleanup for
|
||||
// DBs written by older builds. These tests seed the (still-present) tables via raw
|
||||
// SQL — the only way rows can now exist — and assert the purge empties them.
|
||||
@@ -257,6 +289,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
return (long)(await command.ExecuteScalarAsync())!;
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the central-only purge removes persisted notification list and SMTP rows.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task PurgeCentralOnlyNotificationConfig_RemovesPersistedNotificationListsAndSmtpRows()
|
||||
{
|
||||
@@ -276,6 +310,8 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(0, await RowCountAsync("smtp_configurations"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the central-only purge is idempotent on empty tables.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task PurgeCentralOnlyNotificationConfig_IsIdempotent_OnEmptyTables()
|
||||
{
|
||||
@@ -287,8 +323,10 @@ public class ArtifactStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(0, await RowCountAsync("smtp_configurations"));
|
||||
}
|
||||
|
||||
// ── Schema includes all WP-33 tables ──
|
||||
// ── Schema includes all artifact tables ──
|
||||
|
||||
/// <summary>Verifies that initialization creates all artifact tables.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Initialize_CreatesAllArtifactTables()
|
||||
{
|
||||
|
||||
+42
-2
@@ -8,7 +8,7 @@ using ZB.MOM.WW.ScadaBridge.TestSupport;
|
||||
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// Task 8, site-secrets artifact deploy: site-local <c>deployed_secrets</c>
|
||||
/// Site-secrets artifact deploy: site-local <c>deployed_secrets</c>
|
||||
/// (LocalDb-replicated ciphertext) and <c>mirrored_secrets</c> (node-local ledger) stores.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
@@ -20,19 +20,25 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
private readonly TestLocalDb _localDb;
|
||||
private SiteStorageService _storage = null!;
|
||||
|
||||
/// <summary>Initializes the test class and creates the backing storage.</summary>
|
||||
public DeployedSecretsStorageTests()
|
||||
{
|
||||
_localDb = TestLocalDb.CreateTemp("deployed-secrets");
|
||||
}
|
||||
|
||||
/// <summary>Prepares the fixture before the tests run.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_storage = new SiteStorageService(_localDb.Db, NullLogger<SiteStorageService>.Instance);
|
||||
await _storage.InitializeAsync();
|
||||
}
|
||||
|
||||
/// <summary>Releases the resources used by this instance asynchronously.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
/// <summary>Releases the resources used by this instance.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
var path = _localDb.Path;
|
||||
@@ -42,6 +48,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── deployed_secrets: full-set upsert / soft-delete reconciliation ──
|
||||
|
||||
/// <summary>Verifies that an upsert is treated as the full set and marks absent rows as removed.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Upsert_IsFullSet_MarksAbsentRowsRemoved()
|
||||
{
|
||||
@@ -57,6 +65,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.True(rows.Single(r => r.Name == "B").IsRemoved);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the first upsert applies every row and removes nothing.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Upsert_FirstCall_AppliesEveryRow_AndRemovesNothing()
|
||||
{
|
||||
@@ -67,6 +77,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Empty(removed);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a removed row is not reported as removed again when the set is re-applied.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Upsert_ReAppliedRow_IsNotReportedAsRemovedTwice()
|
||||
{
|
||||
@@ -80,6 +92,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Empty(removedSecond);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a removed row can be re-applied and flips back to not removed.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Upsert_RowThatWasRemoved_CanBeReAppliedAndFlipsBackToNotRemoved()
|
||||
{
|
||||
@@ -98,6 +112,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(2, b.Secret.Revision);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that upserting an empty set marks every existing row as removed.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Upsert_EmptySet_MarksEveryExistingRowRemoved()
|
||||
{
|
||||
@@ -112,6 +128,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.All(rows, r => Assert.True(r.IsRemoved));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that reading the deployed secrets round-trips every field of the secret artifact.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetDeployedSecretsAsync_RoundTripsEveryFieldOfTheSecretArtifact()
|
||||
{
|
||||
@@ -138,6 +156,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(art.Description, row.Secret.Description);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that reading the deployed secrets includes rows marked as removed.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetDeployedSecretsAsync_IncludesRemovedRows()
|
||||
{
|
||||
@@ -153,6 +173,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── security: row_json holds only base64 ciphertext, never plaintext ──
|
||||
|
||||
/// <summary>Verifies that the stored row JSON deserializes to a secret artifact with no extra properties.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task RowJson_DeserializesToSecretArtifact_WithNoExtraProperties()
|
||||
{
|
||||
@@ -204,6 +226,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(expected, propertyNames);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the stored row JSON encodes every byte-array field as Base64 text.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task RowJson_EncodesEveryByteArrayField_AsBase64Text()
|
||||
{
|
||||
@@ -244,6 +268,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── mirrored_secrets: node-local ledger ──
|
||||
|
||||
/// <summary>Verifies that a mirrored secret that is set can be read back.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task MirroredSecrets_SetThenGet_RoundTrips()
|
||||
{
|
||||
@@ -256,6 +282,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(3, row.Revision);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting a mirrored secret twice updates the existing entry.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task MirroredSecrets_Set_IsUpsert()
|
||||
{
|
||||
@@ -268,6 +296,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(2, row.Revision);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that removing a mirrored secret deletes its ledger row.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task MirroredSecrets_Remove_DeletesTheLedgerRow()
|
||||
{
|
||||
@@ -278,6 +308,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Empty(await _storage.GetMirroredSecretsAsync());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that removing an unknown mirrored secret name does nothing.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task MirroredSecrets_Remove_OfAnUnknownName_IsANoOp()
|
||||
{
|
||||
@@ -286,6 +318,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Empty(await _storage.GetMirroredSecretsAsync());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the mirrored-secrets ledger is independent of the deployed secrets.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task MirroredSecrets_IsIndependentOf_DeployedSecrets()
|
||||
{
|
||||
@@ -304,8 +338,10 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("A", mirrored.Name);
|
||||
}
|
||||
|
||||
// ── secret_mirror_status (review finding M1) ──
|
||||
// ── secret_mirror_status (standby mirror failures) ──
|
||||
|
||||
/// <summary>Verifies that mirror status round-trips with one row per node, ordered by node name.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SecretMirrorStatus_RoundTrips_OneRowPerNode_OrderedByNodeName()
|
||||
{
|
||||
@@ -324,6 +360,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(at, rows[1].CheckedAtUtc);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting the mirror status updates that node's existing row.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SecretMirrorStatus_Set_UpsertsTheNodesRow()
|
||||
{
|
||||
@@ -336,6 +374,8 @@ public class DeployedSecretsStorageTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(at.AddHours(1), row.CheckedAtUtc);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that an unparseable mirror status row reads as a failure rather than as healthy.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SecretMirrorStatus_UnparseableRow_ReadsAsAFailure_NotAsHealthy()
|
||||
{
|
||||
|
||||
+17
-1
@@ -5,7 +5,7 @@ using ZB.MOM.WW.ScadaBridge.TestSupport;
|
||||
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// Task 14: site-local SQLite <c>native_alarm_state</c> store — mirrored native alarm
|
||||
/// Site-local SQLite <c>native_alarm_state</c> store — mirrored native alarm
|
||||
/// condition snapshots keyed by (instance, source canonical name, source reference).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
@@ -17,19 +17,26 @@ public class NativeAlarmStateStoreTests : IAsyncLifetime, IDisposable
|
||||
private readonly TestLocalDb _localDb;
|
||||
private SiteStorageService _storage = null!;
|
||||
|
||||
/// <summary>Initializes the tests with a temporary local database.</summary>
|
||||
public NativeAlarmStateStoreTests()
|
||||
{
|
||||
_localDb = TestLocalDb.CreateTemp("nas");
|
||||
}
|
||||
|
||||
/// <summary>Prepares the test fixture before the first test runs.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_storage = new SiteStorageService(_localDb.Db, NullLogger<SiteStorageService>.Instance);
|
||||
await _storage.InitializeAsync();
|
||||
}
|
||||
|
||||
/// <summary>Does nothing; cleanup happens in <c>Dispose</c>.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
/// <summary>Verifies that an upserted alarm row can be read back unchanged.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Upsert_Then_Get_RoundTrips()
|
||||
{
|
||||
@@ -43,6 +50,8 @@ public class NativeAlarmStateStoreTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(DateTimeOffset.UnixEpoch, rows[0].LastTransitionAt);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that upserting the same key replaces the condition and timestamp.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Upsert_SameKey_ReplacesConditionAndTimestamp()
|
||||
{
|
||||
@@ -56,6 +65,8 @@ public class NativeAlarmStateStoreTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(DateTimeOffset.UnixEpoch.AddMinutes(5), rows[0].LastTransitionAt);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a read is scoped to the instance and source canonical name.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Get_ScopesToInstanceAndSourceCanonicalName()
|
||||
{
|
||||
@@ -69,6 +80,8 @@ public class NativeAlarmStateStoreTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("Tank01.Hi", rows[0].SourceReference);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deleting removes only the single targeted row.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Delete_RemovesSingleRow()
|
||||
{
|
||||
@@ -82,6 +95,8 @@ public class NativeAlarmStateStoreTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("Tank01.Lo", rows[0].SourceReference);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that clearing an instance removes all of its sources and leaves other instances untouched.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ClearForInstance_RemovesAllSourcesForInstanceOnly()
|
||||
{
|
||||
@@ -96,6 +111,7 @@ public class NativeAlarmStateStoreTests : IAsyncLifetime, IDisposable
|
||||
Assert.Single(await _storage.GetNativeAlarmsAsync("other", "SrcA"));
|
||||
}
|
||||
|
||||
/// <summary>Releases the resources held by this instance.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// Dispose first — the master connection anchors the WAL, so the sidecars
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Persistence;
|
||||
/// </summary>
|
||||
public class SiteStorageSchemaTests
|
||||
{
|
||||
/// <summary>Verifies that applying the schema is idempotent and creates every table.</summary>
|
||||
[Fact]
|
||||
public void Apply_IsIdempotent_AndCreatesEveryTable()
|
||||
{
|
||||
|
||||
+49
-1
@@ -20,11 +20,14 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
private readonly TestLocalDb _localDb;
|
||||
private SiteStorageService _storage = null!;
|
||||
|
||||
/// <summary>Initializes a new instance of the <c>SiteStorageServiceTests</c> class.</summary>
|
||||
public SiteStorageServiceTests()
|
||||
{
|
||||
_localDb = TestLocalDb.CreateTemp("site-storage-test");
|
||||
}
|
||||
|
||||
/// <summary>Prepares the fixture before the tests run.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_storage = new SiteStorageService(
|
||||
@@ -33,8 +36,11 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
await _storage.InitializeAsync();
|
||||
}
|
||||
|
||||
/// <summary>Releases the resources used by this instance asynchronously.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
/// <summary>Releases the resources used by this instance.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// Dispose first — the master connection anchors the WAL, so the sidecars
|
||||
@@ -44,6 +50,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
TestLocalDb.DeleteFiles(path);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that initialization creates the tables without error.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task InitializeAsync_CreatesTablesWithoutError()
|
||||
{
|
||||
@@ -52,6 +60,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
await _storage.InitializeAsync();
|
||||
}
|
||||
|
||||
/// <summary>Verifies that initialization enables the write-ahead-log journal mode.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Initialize_EnablesWalJournalMode()
|
||||
{
|
||||
@@ -72,6 +82,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("wal", mode.ToLowerInvariant());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a stored deployed config can be retrieved unchanged.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreAndRetrieve_DeployedConfig_RoundTrips()
|
||||
{
|
||||
@@ -88,7 +100,7 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.True(configs[0].IsEnabled);
|
||||
}
|
||||
|
||||
// ── Register P1-4: projected single-row reads ──
|
||||
// ── Projected single-row reads ──
|
||||
//
|
||||
// GetAllDeployedConfigsAsync + FirstOrDefault materializes every deployed config —
|
||||
// including every ConfigJson blob — to find one row. These lock in that
|
||||
@@ -98,6 +110,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
// defect here is pure I/O cost, not an observable behavior difference, so these tests
|
||||
// pin the new projection's contract rather than reproduce a behavior bug.
|
||||
|
||||
/// <summary>Verifies that a single-config read returns the same row as reading all configs and picking the match.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetDeployedConfigAsync_ReturnsSameRowAs_GetAllThenFirstOrDefault()
|
||||
{
|
||||
@@ -120,6 +134,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(viaFullScan.DeployedAt, viaProjection.DeployedAt);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that reading the config of an unknown instance returns null.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetDeployedConfigAsync_UnknownInstance_ReturnsNull()
|
||||
{
|
||||
@@ -131,6 +147,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a metadata read returns the same identity as reading all configs and picking the match.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetDeployedConfigMetadataAsync_ReturnsSameIdentityAs_GetAllThenFirstOrDefault()
|
||||
{
|
||||
@@ -151,6 +169,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal(viaFullScan.IsEnabled, metadata.IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that reading the metadata of an unknown instance returns null.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetDeployedConfigMetadataAsync_UnknownInstance_ReturnsNull()
|
||||
{
|
||||
@@ -162,6 +182,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that storing a deployed config for an existing instance replaces the previous row.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreDeployedConfig_Upserts_OnConflict()
|
||||
{
|
||||
@@ -178,6 +200,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.False(configs[0].IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that removing a deployed config also removes its static overrides.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task RemoveDeployedConfig_RemovesConfigAndOverrides()
|
||||
{
|
||||
@@ -194,6 +218,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Empty(overrides);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting the instance enabled state updates the stored flag.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SetInstanceEnabled_UpdatesFlag()
|
||||
{
|
||||
@@ -211,6 +237,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.True(configs[0].IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting the enabled state of a nonexistent instance does not throw.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SetInstanceEnabled_NonExistent_DoesNotThrow()
|
||||
{
|
||||
@@ -220,6 +248,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── Static Override Tests ──
|
||||
|
||||
/// <summary>Verifies that a static override can be stored and read back unchanged.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SetAndGetStaticOverride_RoundTrips()
|
||||
{
|
||||
@@ -231,6 +261,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("98.6", overrides["Temperature"]);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting a static override that already exists replaces its value.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SetStaticOverride_Upserts_OnConflict()
|
||||
{
|
||||
@@ -243,6 +275,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Equal("100.0", overrides["Temperature"]);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that clearing static overrides removes all of an instance's overrides.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ClearStaticOverrides_RemovesAll()
|
||||
{
|
||||
@@ -255,6 +289,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.Empty(overrides);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that static overrides are isolated per instance.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetStaticOverrides_IsolatedPerInstance()
|
||||
{
|
||||
@@ -270,6 +306,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.True(pump2.ContainsKey("Pressure"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that multiple instances have independent lifecycles.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task MultipleInstances_IndependentLifecycle()
|
||||
{
|
||||
@@ -289,6 +327,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
|
||||
// ── Negative Tests ──
|
||||
|
||||
/// <summary>Verifies that the schema does not contain an alarm state table.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Schema_DoesNotContain_AlarmStateTable()
|
||||
{
|
||||
@@ -339,6 +379,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a conditional store inserts the config when no row exists.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreDeployedConfigIfNewer_NoExistingRow_Inserts()
|
||||
{
|
||||
@@ -356,6 +398,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.True(configs[0].IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a conditional store overwrites an existing older row.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreDeployedConfigIfNewer_ExistingOlderRow_Overwrites()
|
||||
{
|
||||
@@ -375,6 +419,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.False(configs[0].IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a conditional store does nothing when the existing row is newer.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreDeployedConfigIfNewer_ExistingNewerRow_IsNoop()
|
||||
{
|
||||
@@ -397,6 +443,8 @@ public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
|
||||
Assert.False(configs[0].IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a conditional store does nothing when the deployment times are equal.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task StoreDeployedConfigIfNewer_EqualDeployedAt_IsNoop()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user