Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/Uns/UnsTreeServiceLoadEditTests.cs
T
2026-06-08 13:20:25 -04:00

69 lines
2.1 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
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.
/// </summary>
[Trait("Category", "Unit")]
public sealed class UnsTreeServiceLoadEditTests
{
private static (UnsTreeService Service, string DbName) Seeded()
{
var dbName = $"uns-loadedit-{Guid.NewGuid():N}";
UnsTreeTestDb.SeedNamed(dbName);
return (new UnsTreeService(UnsTreeTestDb.Factory(dbName)), dbName);
}
/// <summary>Loading a seeded area maps its fields, owning cluster, and a non-empty RowVersion.</summary>
[Fact]
public async Task LoadArea_returns_dto()
{
var (service, _) = Seeded();
var dto = await service.LoadAreaAsync("AREA-1");
dto.ShouldNotBeNull();
dto.UnsAreaId.ShouldBe("AREA-1");
dto.Name.ShouldBe("assembly");
dto.ClusterId.ShouldBe(UnsTreeTestDb.PopulatedClusterId);
dto.RowVersion.ShouldNotBeNull();
}
/// <summary>Loading a missing area returns null.</summary>
[Fact]
public async Task LoadArea_missing_returns_null()
{
var (service, _) = Seeded();
(await service.LoadAreaAsync("NOPE")).ShouldBeNull();
}
/// <summary>Loading a seeded line maps its fields, parent area, and a non-empty RowVersion.</summary>
[Fact]
public async Task LoadLine_returns_dto()
{
var (service, _) = Seeded();
var dto = await service.LoadLineAsync("LINE-1");
dto.ShouldNotBeNull();
dto.UnsLineId.ShouldBe("LINE-1");
dto.UnsAreaId.ShouldBe("AREA-1");
dto.Name.ShouldBe("line-a");
dto.RowVersion.ShouldNotBeNull();
}
/// <summary>Loading a missing line returns null.</summary>
[Fact]
public async Task LoadLine_missing_returns_null()
{
var (service, _) = Seeded();
(await service.LoadLineAsync("NOPE")).ShouldBeNull();
}
}