fix(deployment): read every external system's methods in one query for the artifact snapshot (review 2026-10-21 04/P7)
This commit is contained in:
+31
-3
@@ -1,20 +1,22 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Deployment;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.ExternalSystems;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Retention purge for <see cref="SystemArtifactDeploymentRecord"/> rows (review 2026-10-21
|
||||
/// Artifact-deploy queries on DeploymentManagerRepository. Retention purge for
|
||||
/// <see cref="SystemArtifactDeploymentRecord"/> rows (review 2026-10-21
|
||||
/// 08/G2): one row is written per Deploy Artifacts run and nothing reads them back, so they
|
||||
/// must share the terminal deployment-record retention window.
|
||||
/// </summary>
|
||||
public sealed class SystemArtifactDeploymentPurgeTests : IDisposable
|
||||
public sealed class DeploymentManagerArtifactRepositoryTests : IDisposable
|
||||
{
|
||||
private readonly ScadaBridgeDbContext _context = SqliteTestHelper.CreateInMemoryContext();
|
||||
private readonly DeploymentManagerRepository _repository;
|
||||
|
||||
/// <summary>Initializes the repository over a fresh in-memory SQLite context.</summary>
|
||||
public SystemArtifactDeploymentPurgeTests()
|
||||
public DeploymentManagerArtifactRepositoryTests()
|
||||
{
|
||||
_repository = new DeploymentManagerRepository(_context);
|
||||
}
|
||||
@@ -49,4 +51,30 @@ public sealed class SystemArtifactDeploymentPurgeTests : IDisposable
|
||||
var survivor = Assert.Single(remaining);
|
||||
Assert.True(survivor.DeployedAt > cutoff);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// review 2026-10-21 04/P7: the artifact-deploy method read returns every system's methods
|
||||
/// in one untracked query.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetAllExternalSystemMethods_ReturnsEverySystemsMethods_Untracked()
|
||||
{
|
||||
var a = new ExternalSystemDefinition("A", "https://a.test", "ApiKey");
|
||||
var b = new ExternalSystemDefinition("B", "https://b.test", "ApiKey");
|
||||
_context.AddRange(a, b);
|
||||
await _context.SaveChangesAsync();
|
||||
_context.AddRange(
|
||||
new ExternalSystemMethod("A1", "GET", "/a1") { ExternalSystemDefinitionId = a.Id },
|
||||
new ExternalSystemMethod("B1", "GET", "/b1") { ExternalSystemDefinitionId = b.Id },
|
||||
new ExternalSystemMethod("B2", "POST", "/b2") { ExternalSystemDefinitionId = b.Id });
|
||||
await _context.SaveChangesAsync();
|
||||
_context.ChangeTracker.Clear();
|
||||
|
||||
var methods = await _repository.GetAllExternalSystemMethodsAsync();
|
||||
|
||||
Assert.Equal(3, methods.Count);
|
||||
Assert.Equal(2, methods.Count(m => m.ExternalSystemDefinitionId == b.Id));
|
||||
Assert.Empty(_context.ChangeTracker.Entries<ExternalSystemMethod>());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user