using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Xunit;
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
using ZB.MOM.WW.LmxOpcUa.Host.OpcUa;
using ZB.MOM.WW.LmxOpcUa.Tests.Helpers;
namespace ZB.MOM.WW.LmxOpcUa.Tests.Wiring
{
///
/// Verifies: OPC UA Write → NodeManager → IMxAccessClient.WriteAsync with correct tag+value
///
public class OpcUaWriteToMxAccessWiringTest
{
///
/// Confirms that the resolved OPC UA write path targets the expected Galaxy tag reference and payload.
///
[Fact]
public async Task Write_SendsCorrectTagAndValue()
{
var mxClient = new FakeMxAccessClient();
var hierarchy = new List
{
new GalaxyObjectInfo { GobjectId = 1, TagName = "TestMachine_001", BrowseName = "TestMachine_001", ParentGobjectId = 0, IsArea = false }
};
var attributes = new List
{
new GalaxyAttributeInfo { GobjectId = 1, TagName = "TestMachine_001", AttributeName = "MachineCode", FullTagReference = "TestMachine_001.MachineCode", MxDataType = 5, IsArray = false }
};
var model = AddressSpaceBuilder.Build(hierarchy, attributes);
var tagRef = model.NodeIdToTagReference["TestMachine_001.MachineCode"];
// Write through MxAccessClient
var result = await mxClient.WriteAsync(tagRef, "NEW_CODE");
result.ShouldBe(true);
mxClient.WrittenValues.ShouldContain(w => w.Tag == "TestMachine_001.MachineCode" && (string)w.Value == "NEW_CODE");
}
}
}