feat(template): carry ElementDataType through flatten/override

This commit is contained in:
Joseph Doherty
2026-06-16 15:24:31 -04:00
parent e7e34b26f1
commit 02aff2436e
2 changed files with 64 additions and 0 deletions
@@ -788,4 +788,67 @@ public class FlatteningServiceTests
Assert.Equal("ns=2;s=Tank07", result.Value.NativeAlarmSources[0].SourceReference);
Assert.Equal("Override", result.Value.NativeAlarmSources[0].Source);
}
// ── MV-4: ElementDataType carried through flatten/override ────────────
[Fact]
public void Flatten_ListAttribute_ElementDataTypeCarriedToResolvedAttribute()
{
// A template with a List attribute whose ElementDataType is String.
// The flattened result must carry DataType == "List" and ElementDataType == "String".
var template = CreateTemplate(1, "Base");
template.Attributes.Add(new TemplateAttribute("Tags")
{
DataType = DataType.List,
ElementDataType = DataType.String,
Value = null
});
var instance = CreateInstance();
var result = _sut.Flatten(
instance,
[template],
new Dictionary<int, IReadOnlyList<TemplateComposition>>(),
new Dictionary<int, IReadOnlyList<Template>>(),
new Dictionary<int, DataConnection>());
Assert.True(result.IsSuccess);
var attr = result.Value.Attributes.First(a => a.CanonicalName == "Tags");
Assert.Equal("List", attr.DataType);
Assert.Equal("String", attr.ElementDataType);
}
[Fact]
public void Flatten_ListAttributeWithInstanceOverride_ElementDataTypePreservedThroughOverride()
{
// An instance override replaces the VALUE of a List attribute.
// The ElementDataType must survive the override path unchanged.
var template = CreateTemplate(1, "Base");
template.Attributes.Add(new TemplateAttribute("Tags")
{
DataType = DataType.List,
ElementDataType = DataType.String,
Value = "[\"a\",\"b\"]"
});
var instance = CreateInstance();
instance.AttributeOverrides.Add(new InstanceAttributeOverride("Tags")
{
OverrideValue = "[\"x\",\"y\",\"z\"]"
});
var result = _sut.Flatten(
instance,
[template],
new Dictionary<int, IReadOnlyList<TemplateComposition>>(),
new Dictionary<int, IReadOnlyList<Template>>(),
new Dictionary<int, DataConnection>());
Assert.True(result.IsSuccess);
var attr = result.Value.Attributes.First(a => a.CanonicalName == "Tags");
Assert.Equal("[\"x\",\"y\",\"z\"]", attr.Value); // override applied
Assert.Equal("Override", attr.Source); // came from override path
Assert.Equal("List", attr.DataType); // type unchanged
Assert.Equal("String", attr.ElementDataType); // element type preserved
}
}