using ZB.MOM.WW.ScadaBridge.CentralUI.Services; using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Services; public class TemplatePathFormatterTests { private static Dictionary Folders(params TemplateFolder[] f) => f.ToDictionary(x => x.Id); /// Verifies that a root template is formatted as its name only. [Fact] public void RootTemplate_IsNameOnly() { var t = new Template("Motor Controller") { Id = 1, FolderId = null }; Assert.Equal("Motor Controller", TemplatePathFormatter.Format(t, Folders())); } /// Verifies that a nested template is formatted with its folder chain joined by slashes. [Fact] public void NestedTemplate_JoinsFolderChainWithSlashes() { var controllers = new TemplateFolder("Controllers") { Id = 10, ParentFolderId = null }; var conveyor = new TemplateFolder("Conveyor") { Id = 11, ParentFolderId = 10 }; var t = new Template("MES Line Controller") { Id = 1, FolderId = 11 }; Assert.Equal("Controllers / Conveyor / MES Line Controller", TemplatePathFormatter.Format(t, Folders(controllers, conveyor))); } /// Verifies that an unknown folder id falls back to the name only without throwing. [Fact] public void UnknownFolderId_FallsBackToNameOnly_WithoutThrowing() { var t = new Template("Orphan") { Id = 1, FolderId = 999 }; Assert.Equal("Orphan", TemplatePathFormatter.Format(t, Folders())); } /// Verifies that a cycle in the folder chain terminates instead of looping forever. [Fact] public void FolderCycle_Terminates() { var a = new TemplateFolder("A") { Id = 1, ParentFolderId = 2 }; var b = new TemplateFolder("B") { Id = 2, ParentFolderId = 1 }; var t = new Template("T") { Id = 1, FolderId = 1 }; var s = TemplatePathFormatter.Format(t, Folders(a, b)); Assert.EndsWith("T", s); // no hang, no exception } }