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.
116 lines
5.4 KiB
C#
116 lines
5.4 KiB
C#
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
|
using ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
|
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
|
|
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Validation;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
|
|
|
/// <summary>
|
|
/// Proves the FlatteningPipeline actually computes the alarm-capable
|
|
/// connection set from the loaded site data connections and threads it through
|
|
/// ValidationService → SemanticValidator. Before the fix the pipeline loaded the
|
|
/// connections but never passed the capable set, so the native-alarm-source
|
|
/// capability check (built but inert) never ran in production — a source bound to
|
|
/// a non-alarm-capable connection deployed silently.
|
|
/// </summary>
|
|
public class FlatteningPipelineNativeAlarmCapabilityTests
|
|
{
|
|
private const int InstanceId = 1;
|
|
private const int TemplateId = 10;
|
|
private const int SiteId = 100;
|
|
|
|
private readonly ITemplateEngineRepository _templateRepo = Substitute.For<ITemplateEngineRepository>();
|
|
private readonly ISiteRepository _siteRepo = Substitute.For<ISiteRepository>();
|
|
private readonly ISharedSchemaRepository _sharedSchemaRepo = Substitute.For<ISharedSchemaRepository>();
|
|
private readonly FlatteningPipeline _sut;
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="FlatteningPipelineNativeAlarmCapabilityTests"/> class.</summary>
|
|
public FlatteningPipelineNativeAlarmCapabilityTests()
|
|
{
|
|
_sharedSchemaRepo.ListAsync(Arg.Any<CancellationToken>())
|
|
.Returns([]);
|
|
|
|
_sut = new FlatteningPipeline(
|
|
_templateRepo,
|
|
_siteRepo,
|
|
new FlatteningService(),
|
|
new ValidationService(),
|
|
new RevisionHashService(),
|
|
_sharedSchemaRepo,
|
|
new TemplateGraphWatermark());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Seeds a single-template chain whose only template carries one native alarm
|
|
/// source bound to <paramref name="connectionName"/>, and a site that owns a
|
|
/// single data connection of <paramref name="connectionProtocol"/>.
|
|
/// </summary>
|
|
private void Arrange(string connectionName, string connectionProtocol, string boundConnectionName)
|
|
{
|
|
var template = new Template("Tank") { Id = TemplateId };
|
|
template.NativeAlarmSources.Add(new TemplateNativeAlarmSource("BoilerAlarms")
|
|
{
|
|
ConnectionName = boundConnectionName,
|
|
SourceReference = "ns=2;s=Boiler",
|
|
});
|
|
|
|
var instance = new Instance("Tank-01") { Id = InstanceId, TemplateId = TemplateId, SiteId = SiteId };
|
|
|
|
_templateRepo.GetInstanceByIdAsync(InstanceId, Arg.Any<CancellationToken>()).Returns(instance);
|
|
_templateRepo.GetTemplateWithChildrenAsync(TemplateId, Arg.Any<CancellationToken>()).Returns(template);
|
|
_templateRepo.GetCompositionsByTemplateIdAsync(TemplateId, Arg.Any<CancellationToken>())
|
|
.Returns([]);
|
|
_templateRepo.GetAllSharedScriptsAsync(Arg.Any<CancellationToken>())
|
|
.Returns([]);
|
|
|
|
var connection = new DataConnection(connectionName, connectionProtocol, SiteId) { Id = 7 };
|
|
_siteRepo.GetDataConnectionsBySiteIdAsync(SiteId, Arg.Any<CancellationToken>())
|
|
.Returns([connection]);
|
|
}
|
|
|
|
/// <summary>Verifies that a native alarm source on a connection that is not alarm-capable reports a capability error.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task FlattenAndValidate_NativeAlarmSourceOnNonAlarmCapableConnection_ReportsCapabilityError()
|
|
{
|
|
// A "Modbus" connection is NOT alarm-capable (no IAlarmSubscribableConnection adapter).
|
|
Arrange(connectionName: "PlantBus", connectionProtocol: "Modbus", boundConnectionName: "PlantBus");
|
|
|
|
var result = await _sut.FlattenAndValidateAsync(InstanceId);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.Contains(result.Value.Validation.Errors,
|
|
e => e.Category == ValidationCategory.NativeAlarmSourceInvalid
|
|
&& e.Message.Contains("alarm-capable"));
|
|
}
|
|
|
|
/// <summary>Verifies that a native alarm source on an alarm-capable connection reports no capability error.</summary>
|
|
/// <param name="protocol">The data connection protocol under test.</param>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Theory]
|
|
[InlineData("OpcUa")]
|
|
[InlineData("MxGateway")]
|
|
// Case variants: IsAlarmCapable uses OrdinalIgnoreCase, matching DataConnectionFactory's
|
|
// own OrdinalIgnoreCase protocol-key lookup; lock the contract with non-canonical casing.
|
|
[InlineData("OPCUA")]
|
|
[InlineData("opcua")]
|
|
[InlineData("mxgateway")]
|
|
[InlineData("MXGATEWAY")]
|
|
public async Task FlattenAndValidate_NativeAlarmSourceOnAlarmCapableConnection_NoCapabilityError(string protocol)
|
|
{
|
|
Arrange(connectionName: "Boiler", connectionProtocol: protocol, boundConnectionName: "Boiler");
|
|
|
|
var result = await _sut.FlattenAndValidateAsync(InstanceId);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.DoesNotContain(result.Value.Validation.Errors,
|
|
e => e.Category == ValidationCategory.NativeAlarmSourceInvalid);
|
|
}
|
|
}
|