82 lines
3.6 KiB
C#
82 lines
3.6 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
|
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests.Flattening;
|
|
|
|
/// <summary>
|
|
/// Design 2026-08-20 (grouped connection bindings): the flattened attribute
|
|
/// carries the data-source reference as it was BEFORE the instance binding
|
|
/// override, so the Configure page can show the template default next to the
|
|
/// effective reference. The field is deliberately NOT part of the revision hash.
|
|
/// </summary>
|
|
public class DefaultDataSourceReferenceTests
|
|
{
|
|
[Fact]
|
|
public void RevisionHash_IgnoresDefaultDataSourceReference()
|
|
{
|
|
var svc = new RevisionHashService();
|
|
var a = new ResolvedAttribute
|
|
{
|
|
CanonicalName = "LeftMESReceiver.MoveInFlag",
|
|
DataType = "Boolean",
|
|
DataSourceReference = "MESReceiver_022.MoveInFlag",
|
|
BoundDataConnectionId = 1
|
|
};
|
|
var without = new FlattenedConfiguration { InstanceUniqueName = "Z28061", Attributes = [a] };
|
|
var with = without with { Attributes = [a with { DefaultDataSourceReference = "MoveInFlag" }] };
|
|
|
|
Assert.Equal(svc.ComputeHash(without), svc.ComputeHash(with));
|
|
}
|
|
|
|
[Fact]
|
|
public void ResolvedAttribute_DefaultDataSourceReference_IsNullByDefault()
|
|
{
|
|
var a = new ResolvedAttribute { CanonicalName = "X" };
|
|
Assert.Null(a.DefaultDataSourceReference);
|
|
}
|
|
|
|
[Fact]
|
|
public void Flatten_PopulatesDefault_ForBoundAndUnboundDataSourcedAttributes()
|
|
{
|
|
var template = new Template("Base") { Id = 1 };
|
|
template.Attributes.Add(new TemplateAttribute("MoveInFlag") { DataType = DataType.Boolean, DataSourceReference = "MoveInFlag" });
|
|
template.Attributes.Add(new TemplateAttribute("Unbound") { DataType = DataType.Boolean, DataSourceReference = "UnboundRef" });
|
|
template.Attributes.Add(new TemplateAttribute("Static") { DataType = DataType.Boolean, Value = "false" });
|
|
|
|
var instance = new Instance("Z28061") { Id = 1, TemplateId = 1, SiteId = 1 };
|
|
instance.ConnectionBindings.Add(new InstanceConnectionBinding("MoveInFlag")
|
|
{
|
|
DataConnectionId = 1,
|
|
DataSourceReferenceOverride = "MESReceiver_022.MoveInFlag"
|
|
});
|
|
|
|
var connections = new Dictionary<int, DataConnection>
|
|
{
|
|
[1] = new("GW", "MxGateway", 1) { Id = 1, PrimaryConfiguration = "http://localhost" }
|
|
};
|
|
|
|
var result = new FlatteningService().Flatten(
|
|
instance,
|
|
[template],
|
|
new Dictionary<int, IReadOnlyList<TemplateComposition>>(),
|
|
new Dictionary<int, IReadOnlyList<Template>>(),
|
|
connections);
|
|
|
|
Assert.True(result.IsSuccess, result.IsFailure ? result.Error : null);
|
|
var bound = result.Value.Attributes.Single(a => a.CanonicalName == "MoveInFlag");
|
|
Assert.Equal("MESReceiver_022.MoveInFlag", bound.DataSourceReference);
|
|
Assert.Equal("MoveInFlag", bound.DefaultDataSourceReference);
|
|
|
|
var unbound = result.Value.Attributes.Single(a => a.CanonicalName == "Unbound");
|
|
Assert.Equal("UnboundRef", unbound.DataSourceReference);
|
|
Assert.Equal("UnboundRef", unbound.DefaultDataSourceReference);
|
|
|
|
var stat = result.Value.Attributes.Single(a => a.CanonicalName == "Static");
|
|
Assert.Null(stat.DefaultDataSourceReference);
|
|
}
|
|
}
|