fix(transport): carry TemplateAlarm.OnTriggerScript by name in bundle DTO
This commit is contained in:
@@ -79,15 +79,6 @@ public sealed class EntitySerializerTests
|
||||
IsLocked = true,
|
||||
Description = "PSI",
|
||||
});
|
||||
basic.Alarms.Add(new TemplateAlarm("High")
|
||||
{
|
||||
Id = 1,
|
||||
TemplateId = 1,
|
||||
PriorityLevel = 2,
|
||||
TriggerType = AlarmTriggerType.RangeViolation,
|
||||
TriggerConfiguration = "{\"threshold\":100}",
|
||||
IsLocked = false,
|
||||
});
|
||||
basic.Scripts.Add(new TemplateScript("OnUpdate", "return 1;")
|
||||
{
|
||||
Id = 1,
|
||||
@@ -98,6 +89,19 @@ public sealed class EntitySerializerTests
|
||||
IsLocked = false,
|
||||
MinTimeBetweenRuns = TimeSpan.FromSeconds(30),
|
||||
});
|
||||
basic.Alarms.Add(new TemplateAlarm("High")
|
||||
{
|
||||
Id = 1,
|
||||
TemplateId = 1,
|
||||
PriorityLevel = 2,
|
||||
TriggerType = AlarmTriggerType.RangeViolation,
|
||||
TriggerConfiguration = "{\"threshold\":100}",
|
||||
IsLocked = false,
|
||||
// FU-B / #37 — alarm fires "OnUpdate" script when triggered. The FK is
|
||||
// an in-aggregate script id; the DTO carries the name and the
|
||||
// importer resolves the FK on the way back in.
|
||||
OnTriggerScriptId = 1,
|
||||
});
|
||||
|
||||
var assembly = new Template("Assembly") { Id = 2, FolderId = 1 };
|
||||
assembly.Compositions.Add(new TemplateComposition("MotorA")
|
||||
@@ -115,6 +119,15 @@ public sealed class EntitySerializerTests
|
||||
|
||||
var sut = new EntitySerializer();
|
||||
var dto = sut.ToBundleContent(aggregate);
|
||||
|
||||
// FU-B / #37 — verify the DTO carries OnTriggerScriptName by NAME (not id).
|
||||
// The bundle is portable across environments so a script-id FK can't
|
||||
// survive a round-trip; resolution back to a script id is the importer's
|
||||
// job once the parent template's scripts have been re-persisted.
|
||||
var dtoBasic = Assert.Single(dto.Templates, t => t.Name == "Basic");
|
||||
var dtoAlarm = Assert.Single(dtoBasic.Alarms);
|
||||
Assert.Equal("OnUpdate", dtoAlarm.OnTriggerScriptName);
|
||||
|
||||
var roundTripped = sut.FromBundleContent(dto);
|
||||
|
||||
var rtBasic = Assert.Single(roundTripped.Templates, t => t.Name == "Basic");
|
||||
@@ -129,6 +142,9 @@ public sealed class EntitySerializerTests
|
||||
Assert.Equal(AlarmTriggerType.RangeViolation, rtAlarm.TriggerType);
|
||||
Assert.Equal("{\"threshold\":100}", rtAlarm.TriggerConfiguration);
|
||||
Assert.Equal(2, rtAlarm.PriorityLevel);
|
||||
// FromBundleContent leaves OnTriggerScriptId null — the importer
|
||||
// resolves it post-persist when target-DB script ids are known.
|
||||
Assert.Null(rtAlarm.OnTriggerScriptId);
|
||||
|
||||
var rtScript = Assert.Single(rtBasic.Scripts);
|
||||
Assert.Equal("OnUpdate", rtScript.Name);
|
||||
|
||||
Reference in New Issue
Block a user