513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
92 lines
3.8 KiB
C#
92 lines
3.8 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests;
|
|
|
|
/// <summary>
|
|
/// Coverage for <see cref="TemplateNaming.QualifiedName"/> — the computed
|
|
/// hierarchical name of a composition-derived template. Derived templates store
|
|
/// only their contained name (the composition slot's <c>InstanceName</c>); the
|
|
/// dotted path is resolved on read by walking the <c>OwnerCompositionId</c> chain.
|
|
/// </summary>
|
|
public class TemplateNamingTests
|
|
{
|
|
private static (Dictionary<int, Template> byId, Dictionary<int, TemplateComposition> compById)
|
|
BuildGraph(params Template[] templates)
|
|
{
|
|
var byId = templates.ToDictionary(t => t.Id);
|
|
var compById = templates
|
|
.SelectMany(t => t.Compositions)
|
|
.ToDictionary(c => c.Id);
|
|
return (byId, compById);
|
|
}
|
|
|
|
/// <summary>Verifies that a base template's qualified name is just its own name.</summary>
|
|
[Fact]
|
|
public void QualifiedName_BaseTemplate_IsJustItsName()
|
|
{
|
|
var motorController = new Template("Motor Controller") { Id = 4 };
|
|
var (byId, compById) = BuildGraph(motorController);
|
|
|
|
Assert.Equal("Motor Controller", TemplateNaming.QualifiedName(motorController, byId, compById));
|
|
}
|
|
|
|
/// <summary>Verifies that a one-level derived template's qualified name is prefixed with its owner.</summary>
|
|
[Fact]
|
|
public void QualifiedName_OneLevelDerived_PrefixesTheOwner()
|
|
{
|
|
// Motor Controller composes the Pump template into a slot named "Pump".
|
|
var motorController = new Template("Motor Controller") { Id = 4 };
|
|
motorController.Compositions.Add(
|
|
new TemplateComposition("Pump") { Id = 1014, TemplateId = 4, ComposedTemplateId = 2018 });
|
|
var derivedPump = new Template("Pump")
|
|
{
|
|
Id = 2018, IsDerived = true, OwnerCompositionId = 1014
|
|
};
|
|
var (byId, compById) = BuildGraph(motorController, derivedPump);
|
|
|
|
Assert.Equal("Motor Controller.Pump", TemplateNaming.QualifiedName(derivedPump, byId, compById));
|
|
}
|
|
|
|
/// <summary>Verifies that a nested derived template's qualified name walks the whole chain.</summary>
|
|
[Fact]
|
|
public void QualifiedName_NestedDerived_WalksTheWholeChain()
|
|
{
|
|
// Motor Controller -> Pump slot -> TempSensor slot.
|
|
var motorController = new Template("Motor Controller") { Id = 4 };
|
|
motorController.Compositions.Add(
|
|
new TemplateComposition("Pump") { Id = 1014, TemplateId = 4, ComposedTemplateId = 2018 });
|
|
|
|
var derivedPump = new Template("Pump")
|
|
{
|
|
Id = 2018, IsDerived = true, OwnerCompositionId = 1014
|
|
};
|
|
derivedPump.Compositions.Add(
|
|
new TemplateComposition("TempSensor") { Id = 1015, TemplateId = 2018, ComposedTemplateId = 2019 });
|
|
|
|
var derivedTempSensor = new Template("TempSensor")
|
|
{
|
|
Id = 2019, IsDerived = true, OwnerCompositionId = 1015
|
|
};
|
|
var (byId, compById) = BuildGraph(motorController, derivedPump, derivedTempSensor);
|
|
|
|
Assert.Equal(
|
|
"Motor Controller.Pump.TempSensor",
|
|
TemplateNaming.QualifiedName(derivedTempSensor, byId, compById));
|
|
}
|
|
|
|
/// <summary>Verifies that a derived template with a missing owner link falls back to its stored name.</summary>
|
|
[Fact]
|
|
public void QualifiedName_DerivedWithMissingOwnerLink_FallsBackToStoredName()
|
|
{
|
|
// Defensive: a derived template whose owner composition is not in the
|
|
// lookup must not throw — it falls back to the stored contained name.
|
|
var orphan = new Template("TempSensor")
|
|
{
|
|
Id = 2019, IsDerived = true, OwnerCompositionId = 9999
|
|
};
|
|
var (byId, compById) = BuildGraph(orphan);
|
|
|
|
Assert.Equal("TempSensor", TemplateNaming.QualifiedName(orphan, byId, compById));
|
|
}
|
|
}
|