feat(template): carry ElementDataType through flatten/override
This commit is contained in:
@@ -175,6 +175,7 @@ public class FlatteningService
|
||||
CanonicalName = attr.Name,
|
||||
Value = attr.Value,
|
||||
DataType = attr.DataType.ToString(),
|
||||
ElementDataType = attr.ElementDataType?.ToString(),
|
||||
IsLocked = attr.IsLocked,
|
||||
Description = attr.Description,
|
||||
DataSourceReference = attr.DataSourceReference,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user