Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests/DeployedRevisionHashesRepositoryTests.cs
T
Joseph Doherty 513fa1aa16 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.
2026-10-07 15:05:49 -04:00

94 lines
3.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Deployment;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;
/// <summary>
/// Coverage for <c>IDeploymentManagerRepository.GetDeployedRevisionHashesAsync</c> — the
/// fleet-wide InstanceId → RevisionHash projection the pending-updates aggregate reads once
/// per cache TTL. Uses the shared SQLite in-memory fixture with real FK enforcement.
/// </summary>
public class DeployedRevisionHashesRepositoryTests : IDisposable
{
private readonly ScadaBridgeDbContext _context;
private readonly DeploymentManagerRepository _repository;
/// <summary>Creates the in-memory context and the repository under test.</summary>
public DeployedRevisionHashesRepositoryTests()
{
_context = SqliteTestHelper.CreateInMemoryContext();
_repository = new DeploymentManagerRepository(_context);
}
/// <summary>Closes and disposes the in-memory context.</summary>
public void Dispose()
{
_context.Database.CloseConnection();
_context.Dispose();
GC.SuppressFinalize(this);
}
private async Task<int> SeedInstanceAsync(string uniqueName)
{
var site = new Site($"Site-{uniqueName}", $"SI-{uniqueName}");
var template = new Template($"T-{uniqueName}");
_context.Sites.Add(site);
_context.Templates.Add(template);
await _context.SaveChangesAsync();
var instance = new Instance(uniqueName)
{
SiteId = site.Id,
TemplateId = template.Id,
State = InstanceState.Enabled,
};
_context.Instances.Add(instance);
await _context.SaveChangesAsync();
return instance.Id;
}
private async Task SeedSnapshotAsync(int instanceId, string deploymentId, string revisionHash)
{
var snapshot = new DeployedConfigSnapshot(deploymentId, revisionHash, "{\"big\":\"payload\"}")
{
InstanceId = instanceId,
};
_context.Set<DeployedConfigSnapshot>().Add(snapshot);
await _context.SaveChangesAsync();
}
/// <summary>Verifies that the repository returns every deployed snapshot keyed by instance.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task GetDeployedRevisionHashes_returns_every_snapshot_keyed_by_instance()
{
var first = await SeedInstanceAsync("Pump-01");
var second = await SeedInstanceAsync("Pump-02");
await SeedSnapshotAsync(first, "dep-1", "hash-one");
await SeedSnapshotAsync(second, "dep-2", "hash-two");
var hashes = await _repository.GetDeployedRevisionHashesAsync();
Assert.Equal(2, hashes.Count);
Assert.Equal("hash-one", hashes[first]);
Assert.Equal("hash-two", hashes[second]);
}
/// <summary>Verifies that the repository returns an empty result when nothing is deployed.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task GetDeployedRevisionHashes_returns_empty_when_nothing_is_deployed()
{
await SeedInstanceAsync("Pump-01");
var hashes = await _repository.GetDeployedRevisionHashesAsync();
Assert.Empty(hashes);
}
}