feat(uns): equipment modal wired into the tree
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the load-for-edit projections on <see cref="UnsTreeService"/> that prefill the
|
||||
/// Area/Line edit modals and carry the concurrency token back for last-write-wins saves.
|
||||
/// Area/Line/Equipment edit modals and carry the concurrency token back for last-write-wins saves.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class UnsTreeServiceLoadEditTests
|
||||
@@ -65,4 +66,80 @@ public sealed class UnsTreeServiceLoadEditTests
|
||||
|
||||
(await service.LoadLineAsync("NOPE")).ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>Loading the seeded equipment maps its identity fields, line, and a non-empty RowVersion.</summary>
|
||||
[Fact]
|
||||
public async Task LoadEquipment_returns_dto()
|
||||
{
|
||||
var (service, _) = Seeded();
|
||||
|
||||
var dto = await service.LoadEquipmentAsync(UnsTreeTestDb.SeededEquipmentId);
|
||||
|
||||
dto.ShouldNotBeNull();
|
||||
dto.EquipmentId.ShouldBe(UnsTreeTestDb.SeededEquipmentId);
|
||||
dto.Name.ShouldBe("machine-1");
|
||||
dto.MachineCode.ShouldBe("machine_001");
|
||||
dto.UnsLineId.ShouldBe("LINE-1");
|
||||
dto.RowVersion.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>Loading a missing equipment returns null.</summary>
|
||||
[Fact]
|
||||
public async Task LoadEquipment_missing_returns_null()
|
||||
{
|
||||
var (service, _) = Seeded();
|
||||
|
||||
(await service.LoadEquipmentAsync("NOPE")).ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoadDriversForCluster returns every driver in the cluster (any namespace kind), ordered by id,
|
||||
/// with the <c>"{Id} — {Name} ({DriverType})"</c> display; drivers in other clusters are excluded.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task LoadDriversForCluster_returns_cluster_drivers()
|
||||
{
|
||||
var (service, dbName) = Seeded();
|
||||
|
||||
await using (var db = UnsTreeTestDb.CreateNamed(dbName))
|
||||
{
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "DRV-B",
|
||||
ClusterId = UnsTreeTestDb.PopulatedClusterId,
|
||||
NamespaceId = "NS-1",
|
||||
Name = "modbus-b",
|
||||
DriverType = "ModbusTcp",
|
||||
DriverConfig = "{}",
|
||||
});
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "DRV-A",
|
||||
ClusterId = UnsTreeTestDb.PopulatedClusterId,
|
||||
NamespaceId = "NS-1",
|
||||
Name = "galaxy-a",
|
||||
DriverType = "Galaxy",
|
||||
DriverConfig = "{}",
|
||||
});
|
||||
// A driver in a different cluster must be excluded.
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "DRV-OTHER",
|
||||
ClusterId = UnsTreeTestDb.EmptyClusterId,
|
||||
NamespaceId = "NS-2",
|
||||
Name = "other",
|
||||
DriverType = "S7",
|
||||
DriverConfig = "{}",
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var drivers = await service.LoadDriversForClusterAsync(UnsTreeTestDb.PopulatedClusterId);
|
||||
|
||||
drivers.Count.ShouldBe(2);
|
||||
drivers[0].DriverInstanceId.ShouldBe("DRV-A");
|
||||
drivers[0].Display.ShouldBe("DRV-A — galaxy-a (Galaxy)");
|
||||
drivers[1].DriverInstanceId.ShouldBe("DRV-B");
|
||||
drivers[1].Display.ShouldBe("DRV-B — modbus-b (ModbusTcp)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user