perf(deploy): flatten-session caching, bulk DeploySiteAsync, paged management queries
This commit is contained in:
@@ -141,6 +141,22 @@ public class CommandTreeTests
|
||||
Assert.Contains("remove", subNames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deploy_HasSiteVerb_WithRequiredSiteId()
|
||||
{
|
||||
// WP2.5: bulk site deploy. Named `deploy site` to sit alongside
|
||||
// `deploy instance` / `deploy artifacts` — the group's convention is that
|
||||
// the verb names the SCOPE of the deploy.
|
||||
var deploy = DeployCommands.Build(Url, Format, Username, Password);
|
||||
var site = deploy.Subcommands.Single(c => c.Name == "site");
|
||||
|
||||
// --site-id is REQUIRED here, unlike `deploy artifacts` where omitting it
|
||||
// means fleet-wide. A bulk instance deploy must never be accidentally
|
||||
// fleet-wide.
|
||||
Assert.NotEmpty(site.Parse([]).Errors);
|
||||
Assert.Empty(site.Parse(["--site-id", "3"]).Errors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InstanceNativeAlarmSource_HasSetAndClear()
|
||||
{
|
||||
@@ -323,6 +339,7 @@ public class CommandTreeTests
|
||||
[InlineData(typeof(SetInstanceOverridesCommand))]
|
||||
[InlineData(typeof(DebugSnapshotCommand))]
|
||||
[InlineData(typeof(MgmtDeployInstanceCommand))]
|
||||
[InlineData(typeof(MgmtDeploySiteCommand))]
|
||||
[InlineData(typeof(QueryAuditLogCommand))]
|
||||
[InlineData(typeof(ExportBundleCommand))]
|
||||
[InlineData(typeof(PreviewBundleCommand))]
|
||||
|
||||
@@ -8,6 +8,7 @@ using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;
|
||||
|
||||
@@ -120,7 +121,7 @@ public class SplitQueryBehaviourTests : IDisposable
|
||||
public SplitQueryBehaviourTests()
|
||||
{
|
||||
_context = SqliteTestHelper.CreateInMemoryContext();
|
||||
_repository = new TemplateEngineRepository(_context);
|
||||
_repository = new TemplateEngineRepository(_context, new TemplateGraphWatermark());
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;
|
||||
|
||||
@@ -19,7 +20,7 @@ public class TemplateEngineRepositoryTests : IDisposable
|
||||
_context = new ScadaBridgeDbContext(options);
|
||||
_context.Database.OpenConnection();
|
||||
_context.Database.EnsureCreated();
|
||||
_repository = new TemplateEngineRepository(_context);
|
||||
_repository = new TemplateEngineRepository(_context, new TemplateGraphWatermark());
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
using Akka.Actor;
|
||||
using Akka.TestKit.Xunit2;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
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.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Deployment;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.Communication;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// WP2.5: bulk site deployment. Pins the properties that make the fan-out safe —
|
||||
/// concurrency is BOUNDED by the configured degree, one slow instance does not stop
|
||||
/// the others completing, a per-instance timeout contains a wedged instance, and
|
||||
/// every instance still gets its own deployment id and its own operation lock.
|
||||
/// </summary>
|
||||
public class DeploySiteAsyncTests : TestKit
|
||||
{
|
||||
private const int SiteId = 1;
|
||||
|
||||
private readonly IDeploymentManagerRepository _repo = Substitute.For<IDeploymentManagerRepository>();
|
||||
private readonly IFlatteningPipeline _pipeline = Substitute.For<IFlatteningPipeline>();
|
||||
private readonly ISiteRepository _siteRepo = Substitute.For<ISiteRepository>();
|
||||
private readonly IAuditService _audit = Substitute.For<IAuditService>();
|
||||
private readonly OperationLockManager _lockManager = new();
|
||||
|
||||
public DeploySiteAsyncTests()
|
||||
{
|
||||
_siteRepo.GetSiteByIdAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ci => new Site($"Site {ci.ArgAt<int>(0)}", $"site-{ci.ArgAt<int>(0)}") { Id = ci.ArgAt<int>(0) });
|
||||
|
||||
_pipeline.CreateSession().Returns(_ => new FlattenSession(new TemplateGraphWatermark()));
|
||||
}
|
||||
|
||||
/// <summary>Seeds <paramref name="count"/> deployable instances at the test site.</summary>
|
||||
private List<Instance> ArrangeInstances(int count)
|
||||
{
|
||||
var instances = new List<Instance>();
|
||||
for (var i = 1; i <= count; i++)
|
||||
{
|
||||
var instance = new Instance($"Inst-{i:00}")
|
||||
{
|
||||
Id = i,
|
||||
SiteId = SiteId,
|
||||
TemplateId = 10,
|
||||
State = InstanceState.NotDeployed
|
||||
};
|
||||
instances.Add(instance);
|
||||
|
||||
_repo.GetInstanceByIdAsync(i, Arg.Any<CancellationToken>()).Returns(instance);
|
||||
_repo.GetCurrentDeploymentStatusAsync(i, Arg.Any<CancellationToken>()).Returns((DeploymentRecord?)null);
|
||||
|
||||
var config = new FlattenedConfiguration { InstanceUniqueName = instance.UniqueName };
|
||||
_pipeline.FlattenAndValidateAsync(
|
||||
i, Arg.Any<CancellationToken>(), Arg.Any<bool>(), Arg.Any<FlattenSession?>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(config, $"sha256:{i}", ValidationResult.Success())));
|
||||
}
|
||||
|
||||
_siteRepo.GetInstancesBySiteIdAsync(SiteId, Arg.Any<CancellationToken>()).Returns(instances);
|
||||
return instances;
|
||||
}
|
||||
|
||||
private DeploymentService CreateService(IActorRef commActor, int maxParallelism, TimeSpan? perInstanceTimeout = null)
|
||||
{
|
||||
var comms = new CommunicationService(
|
||||
Options.Create(new CommunicationOptions { DeploymentTimeout = TimeSpan.FromSeconds(30) }),
|
||||
NullLogger<CommunicationService>.Instance);
|
||||
comms.SetCommunicationActor(commActor);
|
||||
|
||||
var options = Options.Create(new DeploymentManagerOptions
|
||||
{
|
||||
OperationLockTimeout = TimeSpan.FromSeconds(5),
|
||||
SiteDeploymentMaxParallelism = maxParallelism,
|
||||
SiteDeploymentTimeoutPerInstance = perInstanceTimeout ?? TimeSpan.FromSeconds(30)
|
||||
});
|
||||
|
||||
return new DeploymentService(
|
||||
_repo, _siteRepo, _pipeline, comms, _lockManager, _audit,
|
||||
new DiffService(),
|
||||
new RevisionHashService(),
|
||||
new DeploymentStatusNotifier(NullLogger<DeploymentStatusNotifier>.Instance),
|
||||
options,
|
||||
Options.Create(new CommunicationOptions
|
||||
{
|
||||
CentralFetchBaseUrl = "https://central.test:9000",
|
||||
PendingDeploymentTtl = TimeSpan.FromMinutes(5)
|
||||
}),
|
||||
NullLogger<DeploymentService>.Instance);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeploySiteAsync_SlowInstance_OthersStillComplete_AndConcurrencyIsBounded()
|
||||
{
|
||||
const int instanceCount = 8;
|
||||
const int maxParallelism = 3;
|
||||
ArrangeInstances(instanceCount);
|
||||
|
||||
var tracker = new ConcurrencyTracker();
|
||||
var commActor = Sys.ActorOf(Props.Create(() =>
|
||||
new ThrottledSiteActor(tracker, slowInstanceName: "Inst-01", slowDelay: TimeSpan.FromMilliseconds(400))));
|
||||
|
||||
var service = CreateService(commActor, maxParallelism);
|
||||
|
||||
var result = await service.DeploySiteAsync(SiteId, "admin");
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
var summary = result.Value;
|
||||
|
||||
// Every instance produced a row and all eight completed, including the
|
||||
// seven that were NOT waiting on the slow site round-trip.
|
||||
Assert.Equal(instanceCount, summary.InstanceResults.Count);
|
||||
Assert.Equal(instanceCount, summary.SuccessCount);
|
||||
Assert.Equal(0, summary.FailureCount);
|
||||
|
||||
// The fan-out never exceeded the configured bound.
|
||||
Assert.True(tracker.MaxObserved <= maxParallelism,
|
||||
$"observed {tracker.MaxObserved} concurrent site round-trips, bound was {maxParallelism}");
|
||||
|
||||
// ...and it genuinely WAS concurrent, so the assertion above is not
|
||||
// vacuously satisfied by a serial implementation.
|
||||
Assert.True(tracker.MaxObserved > 1, "site round-trips did not run concurrently at all");
|
||||
|
||||
// Deployment identity: one distinct deployment id per instance.
|
||||
var deploymentIds = summary.InstanceResults.Select(r => r.DeploymentId).ToList();
|
||||
Assert.Equal(instanceCount, deploymentIds.Distinct().Count());
|
||||
Assert.DoesNotContain(deploymentIds, id => string.IsNullOrEmpty(id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeploySiteAsync_WedgedInstance_TimesOutAlone_RestSucceed()
|
||||
{
|
||||
ArrangeInstances(4);
|
||||
|
||||
var tracker = new ConcurrencyTracker();
|
||||
// Instance 2's round-trip is never answered — its per-instance deadline
|
||||
// must contain it rather than stalling the batch.
|
||||
var commActor = Sys.ActorOf(Props.Create(() =>
|
||||
new ThrottledSiteActor(tracker, slowInstanceName: "Inst-02", slowDelay: Timeout.InfiniteTimeSpan)));
|
||||
|
||||
var service = CreateService(commActor, maxParallelism: 4, perInstanceTimeout: TimeSpan.FromMilliseconds(300));
|
||||
|
||||
var result = await service.DeploySiteAsync(SiteId, "admin");
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
var summary = result.Value;
|
||||
|
||||
Assert.Equal(4, summary.InstanceResults.Count);
|
||||
Assert.Equal(3, summary.SuccessCount);
|
||||
Assert.Equal(1, summary.FailureCount);
|
||||
|
||||
var wedged = Assert.Single(summary.InstanceResults, r => !r.Success);
|
||||
Assert.Equal("Inst-02", wedged.UniqueName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeploySiteAsync_ReleasesEveryOperationLock()
|
||||
{
|
||||
ArrangeInstances(5);
|
||||
|
||||
var commActor = Sys.ActorOf(Props.Create(() =>
|
||||
new ThrottledSiteActor(new ConcurrencyTracker(), slowInstanceName: null, slowDelay: TimeSpan.Zero)));
|
||||
|
||||
var service = CreateService(commActor, maxParallelism: 2);
|
||||
|
||||
await service.DeploySiteAsync(SiteId, "admin");
|
||||
|
||||
// The per-instance operation lock is held from prepare through finalize;
|
||||
// once the batch is done every entry must be reclaimed, or a second bulk
|
||||
// deploy of the same site would deadlock on its own leftovers.
|
||||
Assert.Equal(0, _lockManager.TrackedLockCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeploySiteAsync_SiteWithNoInstances_SucceedsWithEmptySummary()
|
||||
{
|
||||
_siteRepo.GetInstancesBySiteIdAsync(SiteId, Arg.Any<CancellationToken>()).Returns([]);
|
||||
|
||||
var commActor = Sys.ActorOf(Props.Create(() =>
|
||||
new ThrottledSiteActor(new ConcurrencyTracker(), slowInstanceName: null, slowDelay: TimeSpan.Zero)));
|
||||
|
||||
var result = await CreateService(commActor, maxParallelism: 2).DeploySiteAsync(SiteId, "admin");
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Empty(result.Value.InstanceResults);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeploySiteAsync_UnknownSite_ReturnsFailure()
|
||||
{
|
||||
_siteRepo.GetSiteByIdAsync(99, Arg.Any<CancellationToken>()).Returns((Site?)null);
|
||||
|
||||
var commActor = Sys.ActorOf(Props.Create(() =>
|
||||
new ThrottledSiteActor(new ConcurrencyTracker(), slowInstanceName: null, slowDelay: TimeSpan.Zero)));
|
||||
|
||||
var result = await CreateService(commActor, maxParallelism: 2).DeploySiteAsync(99, "admin");
|
||||
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Contains("not found", result.Error);
|
||||
}
|
||||
|
||||
/// <summary>Records the peak number of simultaneously in-flight site round-trips.</summary>
|
||||
private sealed class ConcurrencyTracker
|
||||
{
|
||||
private int _current;
|
||||
private int _max;
|
||||
|
||||
/// <summary>Highest simultaneous in-flight count observed.</summary>
|
||||
public int MaxObserved => Volatile.Read(ref _max);
|
||||
|
||||
/// <summary>Marks one round-trip as started and updates the peak.</summary>
|
||||
public void Enter()
|
||||
{
|
||||
var now = Interlocked.Increment(ref _current);
|
||||
int observed;
|
||||
while (now > (observed = Volatile.Read(ref _max)))
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref _max, now, observed) == observed)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Marks one round-trip as finished.</summary>
|
||||
public void Exit() => Interlocked.Decrement(ref _current);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stand-in site that answers <c>RefreshDeploymentCommand</c> with Success,
|
||||
/// optionally delaying (or never answering) one named instance so the test can
|
||||
/// observe the fan-out's bound and its per-instance deadline.
|
||||
///
|
||||
/// <para>
|
||||
/// The reply is scheduled rather than sent inline, so the actor's mailbox is
|
||||
/// not the thing serialising the batch — otherwise the concurrency the test is
|
||||
/// measuring would be an artefact of the harness.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
private sealed class ThrottledSiteActor : ReceiveActor
|
||||
{
|
||||
public ThrottledSiteActor(ConcurrencyTracker tracker, string? slowInstanceName, TimeSpan slowDelay)
|
||||
{
|
||||
Receive<SiteEnvelope>(env =>
|
||||
{
|
||||
if (env.Message is not RefreshDeploymentCommand cmd)
|
||||
return;
|
||||
|
||||
var replyTo = Sender;
|
||||
var isSlow = slowInstanceName != null && cmd.InstanceUniqueName == slowInstanceName;
|
||||
|
||||
if (isSlow && slowDelay == Timeout.InfiniteTimeSpan)
|
||||
{
|
||||
// Never answer: the caller's per-instance deadline must fire.
|
||||
tracker.Enter();
|
||||
return;
|
||||
}
|
||||
|
||||
var delay = isSlow ? slowDelay : TimeSpan.FromMilliseconds(60);
|
||||
tracker.Enter();
|
||||
Context.System.Scheduler.Advanced.ScheduleOnce(delay, () =>
|
||||
{
|
||||
tracker.Exit();
|
||||
replyTo.Tell(new DeploymentStatusResponse(
|
||||
cmd.DeploymentId, cmd.InstanceUniqueName,
|
||||
DeploymentStatus.Success, null, DateTimeOffset.UtcNow));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Validation;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
||||
|
||||
@@ -75,7 +76,8 @@ public class DeploymentComparisonTests
|
||||
new FlatteningService(),
|
||||
new ValidationService(),
|
||||
new RevisionHashService(),
|
||||
sharedSchemaRepo);
|
||||
sharedSchemaRepo,
|
||||
new TemplateGraphWatermark());
|
||||
}
|
||||
|
||||
private static (ITemplateEngineRepository, ISiteRepository, ISharedSchemaRepository) ArrangeNonCompilingScript()
|
||||
|
||||
@@ -17,6 +17,7 @@ using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.Communication;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
||||
|
||||
@@ -641,15 +642,21 @@ public class DeploymentServiceTests : TestKit
|
||||
public async Task StaleInstanceProbe_RequestsValidateScriptsFalse()
|
||||
{
|
||||
// The Transport stale-instance probe also only needs the hash — same skip.
|
||||
_pipeline.FlattenAndValidateAsync(5, Arg.Any<CancellationToken>(), Arg.Any<bool>())
|
||||
// The probe memoises per-instance against the graph watermark, so start
|
||||
// from a clean memo or a sibling test's entry would satisfy the probe
|
||||
// without a flatten at all.
|
||||
StaleInstanceProbe.ClearMemos();
|
||||
|
||||
_pipeline.CreateSession().Returns(_ => new FlattenSession(new TemplateGraphWatermark()));
|
||||
_pipeline.FlattenAndValidateAsync(5, Arg.Any<CancellationToken>(), Arg.Any<bool>(), Arg.Any<FlattenSession?>())
|
||||
.Returns(Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(new FlattenedConfiguration(), "sha256:probe", ValidationResult.Success())));
|
||||
var probe = new StaleInstanceProbe(_pipeline);
|
||||
var probe = new StaleInstanceProbe(_pipeline, new TemplateGraphWatermark());
|
||||
|
||||
var hash = await probe.GetCurrentRevisionHashAsync(5);
|
||||
|
||||
Assert.Equal("sha256:probe", hash);
|
||||
await _pipeline.Received(1).FlattenAndValidateAsync(5, Arg.Any<CancellationToken>(), false);
|
||||
await _pipeline.Received(1).FlattenAndValidateAsync(5, Arg.Any<CancellationToken>(), false, Arg.Any<FlattenSession?>());
|
||||
}
|
||||
|
||||
// ── DeploymentManager-007: comparison must produce a structured diff ──
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
using NSubstitute;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Validation;
|
||||
using Template = ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates.Template;
|
||||
using TemplateAttribute = ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates.TemplateAttribute;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// WP2.5: the flatten-session cache. Pins the two properties the bulk deploy path
|
||||
/// depends on — that N instances sharing a template chain load that chain ONCE per
|
||||
/// session, and that a template mutation (observed through the watermark)
|
||||
/// invalidates the memo so a session can never serve stale template state.
|
||||
/// </summary>
|
||||
public class FlattenSessionCacheTests
|
||||
{
|
||||
private const int TemplateId = 10;
|
||||
private const int ParentTemplateId = 9;
|
||||
private const int SiteId = 100;
|
||||
|
||||
private readonly ITemplateEngineRepository _templateRepo = Substitute.For<ITemplateEngineRepository>();
|
||||
private readonly ISiteRepository _siteRepo = Substitute.For<ISiteRepository>();
|
||||
private readonly ISharedSchemaRepository _sharedSchemaRepo = Substitute.For<ISharedSchemaRepository>();
|
||||
private readonly TemplateGraphWatermark _watermark = new();
|
||||
private readonly FlatteningPipeline _sut;
|
||||
|
||||
public FlattenSessionCacheTests()
|
||||
{
|
||||
_sharedSchemaRepo.ListAsync(Arg.Any<CancellationToken>()).Returns([]);
|
||||
_templateRepo.GetAllSharedScriptsAsync(Arg.Any<CancellationToken>()).Returns([]);
|
||||
_siteRepo.GetDataConnectionsBySiteIdAsync(SiteId, Arg.Any<CancellationToken>()).Returns([]);
|
||||
|
||||
_sut = new FlatteningPipeline(
|
||||
_templateRepo,
|
||||
_siteRepo,
|
||||
new FlatteningService(),
|
||||
new ValidationService(),
|
||||
new RevisionHashService(),
|
||||
_sharedSchemaRepo,
|
||||
_watermark);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds a two-link inheritance chain (Tank -> TankBase) and
|
||||
/// <paramref name="instanceCount"/> instances that all derive from it.
|
||||
/// </summary>
|
||||
private void ArrangeSharedChain(int instanceCount)
|
||||
{
|
||||
var parent = new Template("TankBase") { Id = ParentTemplateId };
|
||||
parent.Attributes.Add(new TemplateAttribute("Serial") { DataType = DataType.String, Value = "x" });
|
||||
|
||||
var template = new Template("Tank") { Id = TemplateId, ParentTemplateId = ParentTemplateId };
|
||||
template.Attributes.Add(new TemplateAttribute("Temp") { DataType = DataType.Double, Value = "0" });
|
||||
|
||||
_templateRepo.GetTemplateWithChildrenAsync(TemplateId, Arg.Any<CancellationToken>()).Returns(template);
|
||||
_templateRepo.GetTemplateWithChildrenAsync(ParentTemplateId, Arg.Any<CancellationToken>()).Returns(parent);
|
||||
_templateRepo.GetCompositionsByTemplateIdAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()).Returns([]);
|
||||
|
||||
for (var i = 1; i <= instanceCount; i++)
|
||||
{
|
||||
var instance = new Instance($"Tank-{i:00}") { Id = i, TemplateId = TemplateId, SiteId = SiteId };
|
||||
_templateRepo.GetInstanceByIdAsync(i, Arg.Any<CancellationToken>()).Returns(instance);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SharedSession_TenInstancesOneTemplate_LoadsEachTemplateOnce()
|
||||
{
|
||||
const int instanceCount = 10;
|
||||
ArrangeSharedChain(instanceCount);
|
||||
|
||||
var session = _sut.CreateSession();
|
||||
for (var i = 1; i <= instanceCount; i++)
|
||||
{
|
||||
var result = await _sut.FlattenAndValidateAsync(i, CancellationToken.None, validateScripts: false, session);
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
// Two templates in the chain, each read exactly once across ten flattens.
|
||||
await _templateRepo.Received(1).GetTemplateWithChildrenAsync(TemplateId, Arg.Any<CancellationToken>());
|
||||
await _templateRepo.Received(1).GetTemplateWithChildrenAsync(ParentTemplateId, Arg.Any<CancellationToken>());
|
||||
|
||||
// The chain walk itself ran once, not once per instance.
|
||||
Assert.Equal(1, session.ChainLoads);
|
||||
Assert.Equal(2, session.TemplateLoads);
|
||||
|
||||
// The session-global queries were hoisted out of the per-instance loop:
|
||||
// shared scripts + schema library once each, site connections once.
|
||||
await _templateRepo.Received(1).GetAllSharedScriptsAsync(Arg.Any<CancellationToken>());
|
||||
await _sharedSchemaRepo.Received(1).ListAsync(Arg.Any<CancellationToken>());
|
||||
await _siteRepo.Received(1).GetDataConnectionsBySiteIdAsync(SiteId, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NoSharedSession_EveryInstanceReloadsTheChain()
|
||||
{
|
||||
const int instanceCount = 4;
|
||||
ArrangeSharedChain(instanceCount);
|
||||
|
||||
// Baseline: without a shared session each flatten gets its own private
|
||||
// one, which is the pre-WP2.5 behaviour the batch path improves on.
|
||||
for (var i = 1; i <= instanceCount; i++)
|
||||
{
|
||||
var result = await _sut.FlattenAndValidateAsync(i, CancellationToken.None, validateScripts: false);
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
await _templateRepo.Received(instanceCount)
|
||||
.GetTemplateWithChildrenAsync(TemplateId, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TemplateMutation_InvalidatesMemo_SoSessionNeverServesStaleState()
|
||||
{
|
||||
ArrangeSharedChain(instanceCount: 2);
|
||||
|
||||
var session = _sut.CreateSession();
|
||||
Assert.True((await _sut.FlattenAndValidateAsync(1, CancellationToken.None, validateScripts: false, session)).IsSuccess);
|
||||
|
||||
// A template edit lands (the repository bumps the watermark on commit).
|
||||
_watermark.BumpTemplate(TemplateId);
|
||||
|
||||
Assert.True((await _sut.FlattenAndValidateAsync(2, CancellationToken.None, validateScripts: false, session)).IsSuccess);
|
||||
|
||||
// The edited template was re-read rather than served from the memo. The
|
||||
// untouched parent stayed cached — invalidation is per-template, not a
|
||||
// whole-session reset.
|
||||
await _templateRepo.Received(2).GetTemplateWithChildrenAsync(TemplateId, Arg.Any<CancellationToken>());
|
||||
await _templateRepo.Received(1).GetTemplateWithChildrenAsync(ParentTemplateId, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StructuralMutation_InvalidatesCachedChainMembership()
|
||||
{
|
||||
ArrangeSharedChain(instanceCount: 2);
|
||||
|
||||
var session = _sut.CreateSession();
|
||||
Assert.True((await _sut.FlattenAndValidateAsync(1, CancellationToken.None, validateScripts: false, session)).IsSuccess);
|
||||
Assert.Equal(1, session.ChainLoads);
|
||||
|
||||
// A re-parent / composition change: chain MEMBERSHIP may now differ, so the
|
||||
// cached chain must be discarded even though each member's own version is
|
||||
// unchanged.
|
||||
_watermark.BumpTemplate(TemplateId, structural: true);
|
||||
|
||||
Assert.True((await _sut.FlattenAndValidateAsync(2, CancellationToken.None, validateScripts: false, session)).IsSuccess);
|
||||
Assert.Equal(2, session.ChainLoads);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -8,6 +8,7 @@ using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Validation;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
||||
|
||||
@@ -40,7 +41,8 @@ public class FlatteningPipelineConnectionBindingTests
|
||||
new FlatteningService(),
|
||||
new ValidationService(),
|
||||
new RevisionHashService(),
|
||||
_sharedSchemaRepo);
|
||||
_sharedSchemaRepo,
|
||||
new TemplateGraphWatermark());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+3
-1
@@ -7,6 +7,7 @@ using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Validation;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
||||
|
||||
@@ -40,7 +41,8 @@ public class FlatteningPipelineNativeAlarmCapabilityTests
|
||||
new FlatteningService(),
|
||||
new ValidationService(),
|
||||
new RevisionHashService(),
|
||||
_sharedSchemaRepo);
|
||||
_sharedSchemaRepo,
|
||||
new TemplateGraphWatermark());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -18,7 +18,10 @@ using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Deployment;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
using ZB.MOM.WW.ScadaBridge.ManagementService;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine;
|
||||
@@ -242,13 +245,14 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
[Fact]
|
||||
public void ListTemplatesCommand_ReturnsTemplateData()
|
||||
{
|
||||
var templates = new List<Template>
|
||||
{
|
||||
new("PumpTemplate") { Id = 1, Description = "Pump" },
|
||||
new("ValveTemplate") { Id = 2, Description = "Valve" }
|
||||
};
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(templates);
|
||||
// ListTemplates now reads DB-side row summaries rather than materialising
|
||||
// every template's full child graph and paging it in memory.
|
||||
_templateRepo.GetTemplateSummariesAsync(Arg.Any<int>(), Arg.Any<int?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<TemplateSummary>
|
||||
{
|
||||
new(1, "PumpTemplate", "Pump", null, null, false, null, 0, 0, 0, 0, 0),
|
||||
new(2, "ValveTemplate", "Valve", null, null, false, null, 0, 0, 0, 0, 0)
|
||||
});
|
||||
|
||||
var actor = CreateActor();
|
||||
var envelope = Envelope(new ListTemplatesCommand());
|
||||
@@ -343,7 +347,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
[Fact]
|
||||
public void ListTemplatesCommand_WhenRepoThrows_ReturnsManagementError()
|
||||
{
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_templateRepo.GetTemplateSummariesAsync(Arg.Any<int>(), Arg.Any<int?>(), Arg.Any<CancellationToken>())
|
||||
.ThrowsAsync(new InvalidOperationException("Database connection lost"));
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -1138,6 +1142,74 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
private static Commons.Entities.Deployment.DeploymentRecord DeploymentRecordFor(int instanceId) =>
|
||||
new("deploy-" + instanceId, "operator") { Id = instanceId, InstanceId = instanceId };
|
||||
|
||||
/// <summary>
|
||||
/// Row-summary equivalent of <see cref="DeploymentRecordFor"/>. QueryDeployments
|
||||
/// now returns DB-side projections instead of whole tracked entities.
|
||||
/// </summary>
|
||||
private static DeploymentRecordSummary DeploymentSummaryFor(int instanceId) =>
|
||||
new(instanceId, "deploy-" + instanceId, instanceId, DeploymentStatus.Success,
|
||||
null, "operator", DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, null);
|
||||
|
||||
/// <summary>
|
||||
/// Stubs <c>QueryDeploymentSummariesAsync</c> so it applies the same
|
||||
/// instance / status / scope / paging predicates the database would.
|
||||
///
|
||||
/// <para>
|
||||
/// The filtering moved OUT of the handler and INTO the query, so a stub that
|
||||
/// ignored the arguments would make these tests pass no matter what the handler
|
||||
/// passed down. Honouring them here is what keeps the scope-enforcement
|
||||
/// assertions meaningful.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
private static void StubDeploymentSummaryQuery(
|
||||
IDeploymentManagerRepository repo,
|
||||
IEnumerable<int> instanceIds)
|
||||
{
|
||||
var rows = instanceIds.Select(DeploymentSummaryFor).ToList();
|
||||
repo.QueryDeploymentSummariesAsync(
|
||||
Arg.Any<int?>(), Arg.Any<DeploymentStatus?>(), Arg.Any<IReadOnlyCollection<int>?>(),
|
||||
Arg.Any<int>(), Arg.Any<int?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ci =>
|
||||
{
|
||||
var instanceId = ci.ArgAt<int?>(0);
|
||||
var scope = ci.ArgAt<IReadOnlyCollection<int>?>(2);
|
||||
var skip = ci.ArgAt<int>(3);
|
||||
var take = ci.ArgAt<int?>(4);
|
||||
|
||||
IEnumerable<DeploymentRecordSummary> q = rows;
|
||||
if (instanceId.HasValue)
|
||||
q = q.Where(r => r.InstanceId == instanceId.Value);
|
||||
if (scope != null)
|
||||
q = q.Where(r => scope.Contains(r.InstanceId));
|
||||
q = q.Skip(Math.Max(0, skip));
|
||||
if (take is > 0)
|
||||
q = q.Take(take.Value);
|
||||
return (IReadOnlyList<DeploymentRecordSummary>)q.ToList();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stubs <c>GetTemplateSummariesAsync</c> over <paramref name="count"/> synthetic
|
||||
/// templates, applying the requested Skip/Take exactly as the database would.
|
||||
/// </summary>
|
||||
private void StubTemplateSummaryPaging(int count)
|
||||
{
|
||||
var rows = Enumerable.Range(1, count)
|
||||
.Select(i => new TemplateSummary(i, $"T-{i:D3}", null, null, null, false, null, 0, 0, 0, 0, 0))
|
||||
.ToList();
|
||||
|
||||
_templateRepo.GetTemplateSummariesAsync(Arg.Any<int>(), Arg.Any<int?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ci =>
|
||||
{
|
||||
var skip = ci.ArgAt<int>(0);
|
||||
var take = ci.ArgAt<int?>(1);
|
||||
IEnumerable<TemplateSummary> q = rows.Skip(Math.Max(0, skip));
|
||||
if (take is > 0)
|
||||
q = q.Take(take.Value);
|
||||
return (IReadOnlyList<TemplateSummary>)q.ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueryDeployments_WithDesignRole_ReturnsUnauthorized()
|
||||
{
|
||||
@@ -1154,11 +1226,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
public void QueryDeployments_UnfilteredWithDeploymentRole_ReturnsAllRecords()
|
||||
{
|
||||
var deployRepo = Substitute.For<IDeploymentManagerRepository>();
|
||||
deployRepo.GetAllDeploymentRecordsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Commons.Entities.Deployment.DeploymentRecord>
|
||||
{
|
||||
DeploymentRecordFor(1), DeploymentRecordFor(2)
|
||||
});
|
||||
StubDeploymentSummaryQuery(deployRepo, [1, 2]);
|
||||
_services.AddScoped(_ => deployRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -1175,8 +1243,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
public void QueryDeployments_FilteredByInstanceId_ReturnsInstanceRecords()
|
||||
{
|
||||
var deployRepo = Substitute.For<IDeploymentManagerRepository>();
|
||||
deployRepo.GetDeploymentsByInstanceIdAsync(5, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Commons.Entities.Deployment.DeploymentRecord> { DeploymentRecordFor(5) });
|
||||
StubDeploymentSummaryQuery(deployRepo, [5]);
|
||||
_services.AddScoped(_ => deployRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -1205,7 +1272,8 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
var response = ExpectMsg<ManagementUnauthorized>(TimeSpan.FromSeconds(5));
|
||||
Assert.Equal(envelope.CorrelationId, response.CorrelationId);
|
||||
// The out-of-scope instance's deployment history must not be queried.
|
||||
deployRepo.DidNotReceiveWithAnyArgs().GetDeploymentsByInstanceIdAsync(default);
|
||||
deployRepo.DidNotReceiveWithAnyArgs().QueryDeploymentSummariesAsync(
|
||||
default, default, default, default, default);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1214,8 +1282,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
_templateRepo.GetInstanceByIdAsync(5, Arg.Any<CancellationToken>())
|
||||
.Returns(new Instance("Pump5") { Id = 5, SiteId = 1 });
|
||||
var deployRepo = Substitute.For<IDeploymentManagerRepository>();
|
||||
deployRepo.GetDeploymentsByInstanceIdAsync(5, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Commons.Entities.Deployment.DeploymentRecord> { DeploymentRecordFor(5) });
|
||||
StubDeploymentSummaryQuery(deployRepo, [5]);
|
||||
_services.AddScoped(_ => deployRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -1240,11 +1307,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
new("Pump2") { Id = 2, SiteId = 2 },
|
||||
});
|
||||
var deployRepo = Substitute.For<IDeploymentManagerRepository>();
|
||||
deployRepo.GetAllDeploymentRecordsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Commons.Entities.Deployment.DeploymentRecord>
|
||||
{
|
||||
DeploymentRecordFor(1), DeploymentRecordFor(2)
|
||||
});
|
||||
StubDeploymentSummaryQuery(deployRepo, [1, 2]);
|
||||
_services.AddScoped(_ => deployRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -1276,12 +1339,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
new("Pump3") { Id = 3, SiteId = 1 },
|
||||
});
|
||||
var deployRepo = Substitute.For<IDeploymentManagerRepository>();
|
||||
deployRepo.GetAllDeploymentRecordsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Commons.Entities.Deployment.DeploymentRecord>
|
||||
{
|
||||
DeploymentRecordFor(1), DeploymentRecordFor(2), DeploymentRecordFor(3),
|
||||
DeploymentRecordFor(1), DeploymentRecordFor(3) // duplicates: still no extra lookups
|
||||
});
|
||||
StubDeploymentSummaryQuery(deployRepo, [1, 2, 3]);
|
||||
_services.AddScoped(_ => deployRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -1300,11 +1358,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
// Admin role bypasses site scoping even with PermittedSiteIds set.
|
||||
// (The user also holds Deployment so it passes the role gate.)
|
||||
var deployRepo = Substitute.For<IDeploymentManagerRepository>();
|
||||
deployRepo.GetAllDeploymentRecordsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Commons.Entities.Deployment.DeploymentRecord>
|
||||
{
|
||||
DeploymentRecordFor(1), DeploymentRecordFor(2)
|
||||
});
|
||||
StubDeploymentSummaryQuery(deployRepo, [1, 2]);
|
||||
_services.AddScoped(_ => deployRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -1391,10 +1445,11 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
[Fact]
|
||||
public void ListTemplates_SkipTake_ReturnsRequestedWindow()
|
||||
{
|
||||
var templates = Enumerable.Range(1, 30)
|
||||
.Select(i => new Template($"T-{i:D3}") { Id = i })
|
||||
.ToList();
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>()).Returns(templates);
|
||||
// Paging moved into the repository (DB-side Skip/Take). The stub applies
|
||||
// the same window the database would, so this still pins that the
|
||||
// command's Skip/Take actually reach the query — the bug being that the
|
||||
// handler used to load everything and slice in memory.
|
||||
StubTemplateSummaryPaging(30);
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new ListTemplatesCommand(Skip: 10, Take: 5)));
|
||||
@@ -1410,10 +1465,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
[Fact]
|
||||
public void ListTemplates_DefaultTake_ReturnsAll()
|
||||
{
|
||||
var templates = Enumerable.Range(1, 30)
|
||||
.Select(i => new Template($"T-{i:D3}") { Id = i })
|
||||
.ToList();
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>()).Returns(templates);
|
||||
StubTemplateSummaryPaging(30);
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new ListTemplatesCommand())); // Take = null => unlimited
|
||||
@@ -1527,7 +1579,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
// Repository throws an unanticipated fault carrying sensitive-looking
|
||||
// detail. The raw text must NOT reach the caller.
|
||||
const string secret = "Server=db-internal-prod;constraint FK_secret";
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_templateRepo.GetTemplateSummariesAsync(Arg.Any<int>(), Arg.Any<int?>(), Arg.Any<CancellationToken>())
|
||||
.ThrowsAsync(new InvalidProgramException(secret));
|
||||
|
||||
var actor = CreateActor();
|
||||
|
||||
@@ -118,6 +118,9 @@ public class RequiredRoleMatrixTests
|
||||
// ---- Deployer-only ----------------------------------------------------------
|
||||
["CreateInstance"] = [Roles.Deployer],
|
||||
["MgmtDeployInstance"] = [Roles.Deployer],
|
||||
// Bulk site deploy (WP2.5). Same authority as the single-instance deploy
|
||||
// it batches — it is N of those, not a new class of privilege.
|
||||
["MgmtDeploySite"] = [Roles.Deployer],
|
||||
["MgmtEnableInstance"] = [Roles.Deployer],
|
||||
["MgmtDisableInstance"] = [Roles.Deployer],
|
||||
["MgmtDeleteInstance"] = [Roles.Deployer],
|
||||
|
||||
@@ -57,6 +57,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(parent);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parent });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parent });
|
||||
|
||||
var result = await _service.CreateTemplateAsync("Child", null, 1, "admin");
|
||||
|
||||
@@ -78,7 +80,11 @@ public class TemplateServiceTests
|
||||
var result = await _service.CreateTemplateAsync("Child", null, 1, "admin");
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
// No whole-graph walk of ANY shape — neither the tracked
|
||||
// GetAllTemplatesAsync nor the no-tracking analysis projection that the
|
||||
// collision/acyclicity checks now use.
|
||||
_repoMock.Verify(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()), Times.Never);
|
||||
_repoMock.Verify(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -112,6 +118,8 @@ public class TemplateServiceTests
|
||||
.ReturnsAsync(new List<Instance>());
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var result = await _service.DeleteTemplateAsync(1, "admin");
|
||||
|
||||
@@ -128,6 +136,8 @@ public class TemplateServiceTests
|
||||
.ReturnsAsync(new List<Instance> { new Instance("Pump1") { Id = 1, TemplateId = 1, SiteId = 1 } });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var result = await _service.DeleteTemplateAsync(1, "admin");
|
||||
|
||||
@@ -145,6 +155,8 @@ public class TemplateServiceTests
|
||||
.ReturnsAsync(new List<Instance>());
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parent, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parent, child });
|
||||
|
||||
var result = await _service.DeleteTemplateAsync(1, "admin");
|
||||
|
||||
@@ -164,6 +176,8 @@ public class TemplateServiceTests
|
||||
.ReturnsAsync(new List<Instance>());
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { moduleTemplate, composingTemplate });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { moduleTemplate, composingTemplate });
|
||||
|
||||
var result = await _service.DeleteTemplateAsync(1, "admin");
|
||||
|
||||
@@ -191,6 +205,13 @@ public class TemplateServiceTests
|
||||
new Template("Child") { Id = 2, ParentTemplateId = 1 },
|
||||
composer
|
||||
});
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template>
|
||||
{
|
||||
template,
|
||||
new Template("Child") { Id = 2, ParentTemplateId = 1 },
|
||||
composer
|
||||
});
|
||||
|
||||
var result = await _service.DeleteTemplateAsync(1, "admin");
|
||||
|
||||
@@ -211,6 +232,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var attr = new TemplateAttribute("Temperature") { DataType = DataType.Float, Value = "0.0" };
|
||||
var result = await _service.AddAttributeAsync(1, attr, "admin");
|
||||
@@ -240,6 +263,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(8, It.IsAny<CancellationToken>())).ReturnsAsync(child);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parent, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parent, child });
|
||||
|
||||
var attr = new TemplateAttribute("MoveInType") { DataType = DataType.String, Value = "" };
|
||||
var result = await _service.AddAttributeAsync(8, attr, "admin");
|
||||
@@ -360,6 +385,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var attr = new TemplateAttribute("Temperature") { DataType = DataType.Int32, Value = "not-a-number" };
|
||||
var result = await _service.AddAttributeAsync(1, attr, "admin");
|
||||
@@ -376,6 +403,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var attr = new TemplateAttribute("SetPoints")
|
||||
{
|
||||
@@ -447,6 +476,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var alarm = new TemplateAlarm("HighTemp")
|
||||
{
|
||||
@@ -510,6 +541,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var script = new TemplateScript("OnStart", "return true;") { TriggerType = "Startup" };
|
||||
var result = await _service.AddScriptAsync(1, script, "admin");
|
||||
@@ -610,6 +643,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(moduleTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template, moduleTemplate });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template, moduleTemplate });
|
||||
|
||||
Template? captured = null;
|
||||
_repoMock.Setup(r => r.AddTemplateAsync(It.IsAny<Template>(), It.IsAny<CancellationToken>()))
|
||||
@@ -651,6 +686,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(11, It.IsAny<CancellationToken>())).ReturnsAsync(sensorProbe1);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { pump, sensor, probe, sensorProbe1 });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { pump, sensor, probe, sensorProbe1 });
|
||||
|
||||
var captured = new List<Template>();
|
||||
_repoMock.Setup(r => r.AddTemplateAsync(It.IsAny<Template>(), It.IsAny<CancellationToken>()))
|
||||
@@ -705,6 +742,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(moduleTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template, moduleTemplate, existing });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template, moduleTemplate, existing });
|
||||
|
||||
var captured = new List<Template>();
|
||||
_repoMock.Setup(r => r.AddTemplateAsync(It.IsAny<Template>(), It.IsAny<CancellationToken>()))
|
||||
@@ -871,6 +910,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(baseTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
|
||||
var proposed = new TemplateAttribute("SetPoint") { Value = "99", DataType = DataType.Float, IsInherited = false };
|
||||
var result = await _service.UpdateAttributeAsync(100, proposed, "admin");
|
||||
@@ -892,6 +933,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(baseTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
|
||||
var proposed = new TemplateScript("Sample", "return 2;") { IsInherited = false };
|
||||
var result = await _service.UpdateScriptAsync(200, proposed, "admin");
|
||||
@@ -919,6 +962,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(moduleTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template, moduleTemplate });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template, moduleTemplate });
|
||||
|
||||
Template? captured = null;
|
||||
_repoMock.Setup(r => r.AddTemplateAsync(It.IsAny<Template>(), It.IsAny<CancellationToken>()))
|
||||
@@ -965,6 +1010,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(baseTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
|
||||
var proposed = new TemplateAlarm("HighTemp")
|
||||
{
|
||||
@@ -1003,6 +1050,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(baseTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
|
||||
var proposed = new TemplateAlarm("HighTemp")
|
||||
{
|
||||
@@ -1030,6 +1079,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(baseTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, derived });
|
||||
|
||||
var proposed = new TemplateAttribute("SetPoint") { Value = "99", DataType = DataType.Float, IsInherited = false };
|
||||
var result = await _service.UpdateAttributeAsync(100, proposed, "admin");
|
||||
@@ -1052,6 +1103,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetInstancesByTemplateIdAsync(5, It.IsAny<CancellationToken>())).ReturnsAsync(new List<Instance>());
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, parent, derived });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseTemplate, parent, derived });
|
||||
|
||||
var result = await _service.DeleteTemplateAsync(5, "admin");
|
||||
|
||||
@@ -1083,6 +1136,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
var result = await _service.AddCompositionAsync(1, 1, "self", "admin");
|
||||
|
||||
@@ -1206,6 +1261,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(childTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parentTemplate, childTemplate });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parentTemplate, childTemplate });
|
||||
|
||||
var proposed = new TemplateAttribute("Speed")
|
||||
{
|
||||
@@ -1241,6 +1298,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(childTemplate);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parentTemplate, childTemplate });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { parentTemplate, childTemplate });
|
||||
|
||||
var result = await _service.DeleteAttributeAsync(20, "admin");
|
||||
|
||||
@@ -1295,6 +1354,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(child);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { child });
|
||||
|
||||
var result = await _service.UpdateTemplateAsync(2, "ChildRenamed", null, null, "admin");
|
||||
|
||||
@@ -1313,6 +1374,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(t);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { t });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { t });
|
||||
|
||||
var result = await _service.UpdateTemplateAsync(1, "T", "", null, "admin");
|
||||
|
||||
@@ -1328,6 +1391,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(2, It.IsAny<CancellationToken>())).ReturnsAsync(child);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { child });
|
||||
|
||||
// Idempotent pass — same parent value sent on update should succeed and apply name/description changes.
|
||||
var result = await _service.UpdateTemplateAsync(2, "ChildRenamed", "new", 1, "admin");
|
||||
@@ -1353,6 +1418,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(templateA);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { templateA, templateB, templateC });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { templateA, templateB, templateC });
|
||||
|
||||
var result = await _service.AddCompositionAsync(3, 1, "a1", "admin");
|
||||
|
||||
@@ -1373,6 +1440,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetFolderByIdAsync(7, It.IsAny<CancellationToken>())).ReturnsAsync(folder);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { t });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { t });
|
||||
|
||||
var result = await _service.MoveTemplateAsync(1, 7, "admin");
|
||||
|
||||
@@ -1387,6 +1456,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(t);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { t });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { t });
|
||||
|
||||
var result = await _service.MoveTemplateAsync(1, null, "admin");
|
||||
|
||||
@@ -1422,6 +1493,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetFolderByIdAsync(7, It.IsAny<CancellationToken>())).ReturnsAsync(folder);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { moving, existing });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { moving, existing });
|
||||
|
||||
var result = await _service.MoveTemplateAsync(1, 7, "admin");
|
||||
|
||||
@@ -1444,6 +1517,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetFolderByIdAsync(7, It.IsAny<CancellationToken>())).ReturnsAsync(folder);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { moving, unrelated });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { moving, unrelated });
|
||||
|
||||
var result = await _service.MoveTemplateAsync(1, 7, "admin");
|
||||
|
||||
@@ -1536,6 +1611,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
TemplateAttribute? added = null;
|
||||
_repoMock.Setup(r => r.AddTemplateAttributeAsync(It.IsAny<TemplateAttribute>(), It.IsAny<CancellationToken>()))
|
||||
@@ -1576,6 +1653,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
TemplateAlarm? added = null;
|
||||
_repoMock.Setup(r => r.AddTemplateAlarmAsync(It.IsAny<TemplateAlarm>(), It.IsAny<CancellationToken>()))
|
||||
@@ -1621,6 +1700,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(1, It.IsAny<CancellationToken>())).ReturnsAsync(template);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { template });
|
||||
|
||||
TemplateScript? added = null;
|
||||
_repoMock.Setup(r => r.AddTemplateScriptAsync(It.IsAny<TemplateScript>(), It.IsAny<CancellationToken>()))
|
||||
@@ -1676,6 +1757,8 @@ public class TemplateServiceTests
|
||||
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
var added = new List<TemplateAttribute>();
|
||||
_repoMock.Setup(r => r.AddTemplateAttributeAsync(It.IsAny<TemplateAttribute>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<TemplateAttribute, CancellationToken>((a, _) => added.Add(a))
|
||||
@@ -1707,6 +1790,8 @@ public class TemplateServiceTests
|
||||
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
var deleted = new List<int>();
|
||||
_repoMock.Setup(r => r.DeleteTemplateAttributeAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<int, CancellationToken>((id, _) => deleted.Add(id))
|
||||
@@ -1731,6 +1816,8 @@ public class TemplateServiceTests
|
||||
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
var updated = new List<TemplateAttribute>();
|
||||
_repoMock.Setup(r => r.UpdateTemplateAttributeAsync(It.IsAny<TemplateAttribute>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<TemplateAttribute, CancellationToken>((a, _) => updated.Add(a))
|
||||
@@ -1756,6 +1843,8 @@ public class TemplateServiceTests
|
||||
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
|
||||
var result = await _service.ResyncInheritedMembersAsync(8, "admin");
|
||||
|
||||
@@ -1781,6 +1870,8 @@ public class TemplateServiceTests
|
||||
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, left, right });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, left, right });
|
||||
var added = new List<TemplateAttribute>();
|
||||
_repoMock.Setup(r => r.AddTemplateAttributeAsync(It.IsAny<TemplateAttribute>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<TemplateAttribute, CancellationToken>((a, _) => added.Add(a))
|
||||
@@ -1809,6 +1900,8 @@ public class TemplateServiceTests
|
||||
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
var addedScripts = new List<TemplateScript>();
|
||||
var addedSources = new List<TemplateNativeAlarmSource>();
|
||||
_repoMock.Setup(r => r.AddTemplateScriptAsync(It.IsAny<TemplateScript>(), It.IsAny<CancellationToken>()))
|
||||
@@ -1846,6 +1939,8 @@ public class TemplateServiceTests
|
||||
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
var added = new List<TemplateAttribute>();
|
||||
_repoMock.Setup(r => r.AddTemplateAttributeAsync(It.IsAny<TemplateAttribute>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<TemplateAttribute, CancellationToken>((a, _) => added.Add(a)).Returns(Task.CompletedTask);
|
||||
@@ -1871,6 +1966,8 @@ public class TemplateServiceTests
|
||||
_repoMock.Setup(r => r.GetTemplateByIdAsync(7, It.IsAny<CancellationToken>())).ReturnsAsync(baseT);
|
||||
_repoMock.Setup(r => r.GetAllTemplatesAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
_repoMock.Setup(r => r.GetAllTemplatesForAnalysisAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<Template> { baseT, child });
|
||||
|
||||
var added = new List<TemplateAttribute>();
|
||||
_repoMock.Setup(r => r.AddTemplateAttributeAsync(It.IsAny<TemplateAttribute>(), It.IsAny<CancellationToken>()))
|
||||
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Validation;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// WP2.5: the verdict cache's eviction policy. Overflow used to <c>Clear()</c> the
|
||||
/// whole cache, which re-opened the non-collectible <c>InteractiveAssemblyLoader</c>
|
||||
/// leak the cache exists to bound — every hot script had to be recompiled, and every
|
||||
/// recompile loads another assembly that can never be unloaded. These tests pin the
|
||||
/// replacement: eviction is segmented, so entries in active use survive it.
|
||||
///
|
||||
/// <para>
|
||||
/// Serialised with the other verdict-cache tests: the cache is process-wide static
|
||||
/// state, so two test classes filling it concurrently would see each other's
|
||||
/// entries.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Collection("ScriptCompileVerdictCache")]
|
||||
public class ScriptCompileVerdictCacheEvictionTests
|
||||
{
|
||||
private const string Surface = "TestSurface";
|
||||
|
||||
/// <summary>Entries needed to force at least one generation rotation.</summary>
|
||||
private const int OverflowCount = 5000;
|
||||
|
||||
private static (bool Ok, string? Error) Lookup(string code, Func<(bool, string?)> factory) =>
|
||||
ScriptCompileVerdictCache.GetOrAdd(Surface, code, factory);
|
||||
|
||||
[Fact]
|
||||
public void Overflow_KeepsHotEntry_AndDoesNotClearEverything()
|
||||
{
|
||||
ScriptCompileVerdictCache.Clear();
|
||||
|
||||
const string hotCode = "// the script every deploy re-validates";
|
||||
var hotCompiles = 0;
|
||||
(bool, string?) HotFactory()
|
||||
{
|
||||
hotCompiles++;
|
||||
return (true, null);
|
||||
}
|
||||
|
||||
Lookup(hotCode, HotFactory);
|
||||
Assert.Equal(1, hotCompiles);
|
||||
|
||||
// Push far more distinct scripts through than the cache can hold, touching
|
||||
// the hot entry as we go — which is exactly what a real workload does, and
|
||||
// exactly what wholesale Clear() used to throw away.
|
||||
for (var i = 0; i < OverflowCount; i++)
|
||||
{
|
||||
Lookup($"// filler {i}", static () => (true, null));
|
||||
if (i % 25 == 0)
|
||||
Lookup(hotCode, HotFactory);
|
||||
}
|
||||
|
||||
// At least one rotation happened...
|
||||
Assert.True(ScriptCompileVerdictCache.Evictions > 0,
|
||||
"the overflow did not trigger a single eviction — the test no longer exercises the policy");
|
||||
|
||||
// ...and the hot entry was never recompiled, because a hit in the cold
|
||||
// generation promotes it back into hot rather than letting it age out.
|
||||
Assert.Equal(1, hotCompiles);
|
||||
|
||||
// A final read still hits.
|
||||
var compilesBefore = hotCompiles;
|
||||
Lookup(hotCode, HotFactory);
|
||||
Assert.Equal(compilesBefore, hotCompiles);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Overflow_RetainsRecentEntries_RatherThanDroppingAll()
|
||||
{
|
||||
ScriptCompileVerdictCache.Clear();
|
||||
|
||||
for (var i = 0; i < OverflowCount; i++)
|
||||
Lookup($"// bulk {i}", static () => (true, null));
|
||||
|
||||
Assert.True(ScriptCompileVerdictCache.Evictions > 0);
|
||||
|
||||
// The most recently inserted entry is in the hot generation, so it must
|
||||
// still be cached. Under the old Clear()-on-overflow policy the cache could
|
||||
// be left holding a single entry after a rotation.
|
||||
var recompiled = false;
|
||||
Lookup($"// bulk {OverflowCount - 1}", () =>
|
||||
{
|
||||
recompiled = true;
|
||||
return (true, null);
|
||||
});
|
||||
|
||||
Assert.False(recompiled, "the most recent entry was evicted; eviction is not retaining the hot generation");
|
||||
Assert.True(ScriptCompileVerdictCache.Count > 1,
|
||||
$"cache retained only {ScriptCompileVerdictCache.Count} entries after eviction");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Overflow_KeepsCacheBounded()
|
||||
{
|
||||
ScriptCompileVerdictCache.Clear();
|
||||
|
||||
for (var i = 0; i < OverflowCount; i++)
|
||||
Lookup($"// bounded {i}", static () => (true, null));
|
||||
|
||||
// Two generations of 2048 — the same 4096 ceiling the previous policy had,
|
||||
// now reached by demotion rather than by dropping everything.
|
||||
Assert.True(ScriptCompileVerdictCache.Count <= 4096,
|
||||
$"cache grew to {ScriptCompileVerdictCache.Count} entries, exceeding its two-generation bound");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SurfaceIsPartOfTheKey_AcrossEviction()
|
||||
{
|
||||
ScriptCompileVerdictCache.Clear();
|
||||
|
||||
const string code = "// same body, two surfaces";
|
||||
Lookup(code, static () => (true, null));
|
||||
|
||||
var otherSurfaceCompiled = false;
|
||||
var verdict = ScriptCompileVerdictCache.GetOrAdd("OtherSurface", code, () =>
|
||||
{
|
||||
otherSurfaceCompiled = true;
|
||||
return (false, "not valid against this surface");
|
||||
});
|
||||
|
||||
// A verdict is never interchangeable across globals surfaces, and the
|
||||
// segmented cache must not weaken that.
|
||||
Assert.True(otherSurfaceCompiled);
|
||||
Assert.False(verdict.Ok);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialises every test that touches the process-wide
|
||||
/// <see cref="ScriptCompileVerdictCache"/> static.
|
||||
/// </summary>
|
||||
[CollectionDefinition("ScriptCompileVerdictCache")]
|
||||
public class ScriptCompileVerdictCacheCollection;
|
||||
@@ -10,6 +10,10 @@ namespace ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests.Validation;
|
||||
/// authoritative behavior: bypasses the old substring scan missed are now caught,
|
||||
/// and undefined symbols (which a structural scan could never see) fail compile.
|
||||
/// </summary>
|
||||
// Serialised with ScriptCompileVerdictCacheEvictionTests: both drive the
|
||||
// process-wide ScriptCompileVerdictCache static, and an overflow test running
|
||||
// concurrently would evict the entries these hit-count assertions depend on.
|
||||
[Collection("ScriptCompileVerdictCache")]
|
||||
public class ScriptCompilerTests
|
||||
{
|
||||
private readonly ScriptCompiler _sut = new();
|
||||
|
||||
@@ -12,6 +12,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests;
|
||||
|
||||
@@ -37,6 +38,7 @@ public sealed class CompositionImportTests : IDisposable
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
@@ -11,6 +11,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests;
|
||||
|
||||
@@ -35,6 +36,7 @@ public sealed class ConflictResolutionTests : IDisposable
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
@@ -19,6 +19,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Encryption;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Serialization;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Export;
|
||||
|
||||
@@ -67,6 +68,7 @@ public sealed class BundleExporterTests : IDisposable
|
||||
// ISiteRepository to walk the site/data-connection/instance closure, so it
|
||||
// must be registered or the BuildServiceProvider-time graph resolution for
|
||||
// DependencyResolver fails.
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
@@ -16,6 +16,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Serialization;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -46,6 +47,7 @@ public sealed class AreaTransportTests : IDisposable
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -24,6 +24,7 @@ using ZB.MOM.WW.ScadaBridge.TemplateEngine;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Serialization;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -76,6 +77,7 @@ public sealed class BundleImporterApplyTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -17,6 +17,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Serialization;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -40,6 +41,7 @@ public sealed class BundleImporterPreviewTests : IDisposable
|
||||
var dbName = $"BundleImporterPreviewTests_{Guid.NewGuid()}";
|
||||
services.AddDbContext<ScadaBridgeDbContext>(opts => opts.UseInMemoryDatabase(dbName));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -18,6 +18,7 @@ using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -80,6 +81,7 @@ public sealed class BundleImporterRetryingStrategyTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -19,6 +19,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -81,6 +82,7 @@ public sealed class BundleImporterRollbackFailureTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -12,6 +12,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -52,6 +53,7 @@ public sealed class CreateMissingSiteRelationalTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -13,6 +13,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -38,6 +39,7 @@ public sealed class InheritanceImportTests : IDisposable
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -17,6 +17,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -49,6 +50,7 @@ public sealed class NativeAlarmSourceImportTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -16,6 +16,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Serialization;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -53,6 +54,7 @@ public sealed class SiteInstanceImportTests : IDisposable
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
+2
@@ -16,6 +16,7 @@ using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Serialization;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests.Import;
|
||||
|
||||
@@ -48,6 +49,7 @@ public sealed class TemplateScriptFidelityTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
@@ -21,6 +21,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
using ZB.MOM.WW.ScadaBridge.TemplateEngine;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests;
|
||||
|
||||
@@ -91,6 +92,7 @@ public sealed class RoundTripEquivalenceTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
@@ -16,6 +16,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Serialization;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests;
|
||||
|
||||
@@ -60,6 +61,7 @@ public sealed class RoundTripTests : IDisposable
|
||||
sp.GetRequiredService<DbContextOptions<ScadaBridgeDbContext>>(),
|
||||
sp.GetRequiredService<IDataProtectionProvider>()));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
@@ -15,6 +15,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests;
|
||||
|
||||
@@ -49,6 +50,7 @@ public sealed class SemanticValidatorImportTests : IDisposable
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
@@ -14,6 +14,7 @@ using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport;
|
||||
using ZB.MOM.WW.ScadaBridge.Transport.Import;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Transport.IntegrationTests;
|
||||
|
||||
@@ -38,6 +39,7 @@ public sealed class ValidationFailureTests : IDisposable
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<IExternalSystemRepository, ExternalSystemRepository>();
|
||||
services.AddScoped<INotificationRepository, NotificationRepository>();
|
||||
|
||||
Reference in New Issue
Block a user