Linter/formatter pass across the full codebase. Restores required partial keyword on AXAML code-behind classes that the formatter incorrectly removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
209 lines
7.9 KiB
C#
209 lines
7.9 KiB
C#
using System.Collections.Generic;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
|
|
using ZB.MOM.WW.LmxOpcUa.Host.OpcUa;
|
|
|
|
namespace ZB.MOM.WW.LmxOpcUa.Tests.OpcUa
|
|
{
|
|
public class AddressSpaceDiffTests
|
|
{
|
|
private static GalaxyObjectInfo Obj(int id, string tag, int parent = 0, bool isArea = false)
|
|
{
|
|
return new GalaxyObjectInfo
|
|
{
|
|
GobjectId = id, TagName = tag, BrowseName = tag, ContainedName = tag, ParentGobjectId = parent,
|
|
IsArea = isArea
|
|
};
|
|
}
|
|
|
|
private static GalaxyAttributeInfo Attr(int gobjectId, string name, string tagName = "Obj", int mxDataType = 5)
|
|
{
|
|
return new GalaxyAttributeInfo
|
|
{
|
|
GobjectId = gobjectId, AttributeName = name, FullTagReference = $"{tagName}.{name}",
|
|
MxDataType = mxDataType, TagName = tagName
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that identical Galaxy hierarchy and attribute snapshots produce no incremental rebuild work.
|
|
/// </summary>
|
|
[Fact]
|
|
public void NoChanges_ReturnsEmptySet()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var a = new List<GalaxyAttributeInfo> { Attr(1, "X") };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, a, h, a);
|
|
changed.ShouldBeEmpty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that newly deployed Galaxy objects are flagged for OPC UA subtree creation.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AddedObject_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var newH = new List<GalaxyObjectInfo> { Obj(1, "A"), Obj(2, "B") };
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(2);
|
|
changed.ShouldNotContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that removed Galaxy objects are flagged so their OPC UA subtree can be torn down.
|
|
/// </summary>
|
|
[Fact]
|
|
public void RemovedObject_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A"), Obj(2, "B") };
|
|
var newH = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(2);
|
|
changed.ShouldNotContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that browse-name changes are treated as address-space changes for the affected Galaxy object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ModifiedObject_BrowseNameChange_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var newH = new List<GalaxyObjectInfo>
|
|
{ new() { GobjectId = 1, TagName = "A", BrowseName = "A_Renamed", ContainedName = "A" } };
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that parent changes are treated as subtree moves that require rebuilding the affected object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ModifiedObject_ParentChange_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A"), Obj(2, "B", 1) };
|
|
var newH = new List<GalaxyObjectInfo>
|
|
{
|
|
Obj(1, "A"),
|
|
new() { GobjectId = 2, TagName = "B", BrowseName = "B", ContainedName = "B", ParentGobjectId = 0 }
|
|
};
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that adding a Galaxy attribute marks the owning object for OPC UA variable rebuild.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeAdded_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo> { Attr(1, "X") };
|
|
var newA = new List<GalaxyAttributeInfo> { Attr(1, "X"), Attr(1, "Y") };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that removing a Galaxy attribute marks the owning object for OPC UA variable rebuild.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeRemoved_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo> { Attr(1, "X"), Attr(1, "Y") };
|
|
var newA = new List<GalaxyAttributeInfo> { Attr(1, "X") };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that changes to attribute field metadata such as MX data type trigger rebuild of the owning object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeFieldChange_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo> { Attr(1, "X", mxDataType: 5) };
|
|
var newA = new List<GalaxyAttributeInfo> { Attr(1, "X", mxDataType: 2) };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that security-classification changes are treated as address-space changes for the owning attribute.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeSecurityChange_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo>
|
|
{ new() { GobjectId = 1, AttributeName = "X", FullTagReference = "A.X", SecurityClassification = 1 } };
|
|
var newA = new List<GalaxyAttributeInfo>
|
|
{ new() { GobjectId = 1, AttributeName = "X", FullTagReference = "A.X", SecurityClassification = 2 } };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that subtree expansion includes all descendants of a changed Galaxy object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ExpandToSubtrees_IncludesChildren()
|
|
{
|
|
var h = new List<GalaxyObjectInfo>
|
|
{
|
|
Obj(1, "Root"),
|
|
Obj(2, "Child", 1),
|
|
Obj(3, "Grandchild", 2),
|
|
Obj(4, "Sibling", 1),
|
|
Obj(5, "Unrelated")
|
|
};
|
|
|
|
var changed = new HashSet<int> { 1 };
|
|
var expanded = AddressSpaceDiff.ExpandToSubtrees(changed, h);
|
|
|
|
expanded.ShouldContain(1);
|
|
expanded.ShouldContain(2);
|
|
expanded.ShouldContain(3);
|
|
expanded.ShouldContain(4);
|
|
expanded.ShouldNotContain(5);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that subtree expansion does not introduce unrelated nodes when the changed object is already a leaf.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ExpandToSubtrees_LeafNode_NoExpansion()
|
|
{
|
|
var h = new List<GalaxyObjectInfo>
|
|
{
|
|
Obj(1, "Root"),
|
|
Obj(2, "Child", 1),
|
|
Obj(3, "Sibling", 1)
|
|
};
|
|
|
|
var changed = new HashSet<int> { 2 };
|
|
var expanded = AddressSpaceDiff.ExpandToSubtrees(changed, h);
|
|
|
|
expanded.ShouldContain(2);
|
|
expanded.ShouldNotContain(1);
|
|
expanded.ShouldNotContain(3);
|
|
}
|
|
}
|
|
} |