Files
UA-.NETStandard/tests/Opc.Ua.Server.Tests/AggregatorsTests.cs
romanett 9b034f8291 Enable nullable reference types centrally; migrate all unset and annotations-only projects (#4700)
# Description

Nullable reference types are now enabled once, in `common.props`, and
every project in the repository builds warning-clean with them.

**Configuration**
- `<Nullable>enable</Nullable>` lives in `common.props`. All per-project
`<Nullable>` settings are removed: 178 project files (enable,
annotations, and the `disable` in the three Aot test projects).
- 419 per-file `#nullable enable`/`restore` directives and the 4
`#nullable disable` directives are removed.
- Kept on purpose:
- The 5 `<auto-generated>` schema files (`UANodeSet.cs`, `UA Type
Dictionary.cs`, `OPCBinarySchema.cs`, `SecuredApplication.cs`,
`PInvokeHelper.cs`) keep `#nullable enable`. The compiler ignores the
project setting in generated code, so the directive is required there.
- `tests/Opc.Ua.Interop.LegacyPeer` keeps `disable`. It builds against
the 1.5.378 packages and does not import the repository props.
- `docs/DeveloperGuide.md` and `.github/copilot-instructions.md` now
describe the central setting.

**Migration** (the 43 unset and 13 annotations-only projects, roughly
10k diagnostics)
- **Production code: annotated at the declarations.** Covers
`tools/Opc.Ua.SourceGeneration.Core`, `src/Opc.Ua.Lds.Server` and the
LDS sample.
- Members, parameters and returns are nullable where null actually
flows.
- Null-check helpers carry `[NotNullWhen]` (`IsNull`, `IsValidXmlName`,
`IsMethodTypeDesign`).
- `CoreUtils.Format`, `Utils.Format`, `ITemplateWriter.WriteLine` take
`params object?[]`. `Template.AddReplacement` takes `string?` (rendering
already skips null replacements).
- `IRegisteredServerStore.RegisterAsync` returns
`Task<RegistrationEntry?>`: it returns null when a registration is
removed.
- Dereferences backed by an invariant (for example, the validated model)
use `!`, so runtime behaviour is unchanged.
- **Behavioural changes in production code** (small, deliberate):
- `NodeSetToModelDesign` throws `InvalidOperationException` when the
file is not a NodeSet. Before, it threw a NullReferenceException on the
next line.
- `ModelDesignValidator` starts its lookup tables empty instead of null.
A redundant `if (m_nodes == null) return;` guard is gone.
- **Test code: minimal annotations.**
  - `?` on values that can be null, `!` where the test asserts non-null.
  - `= null!` for fixture members assigned in SetUp.
- `TryGetStructure<T>(out T? x)` where the inferred `T?` broke the
`IEncodeable` constraint.
- A few redundant `== null` checks on structs (`NodeId`, `ArrayOf<T>`)
folded into the adjacent `IsNull`/`Count` checks.

**Notes for reviewers**
- The diff is large (~1,500 files) but almost entirely mechanical: `?`,
`!` and directive removal. The non-annotation changes are listed above.
- Known follow-up, not done here:
`IModelDesign.Namespaces/TargetNamespace/NamespaceUris` stay
non-nullable even though the validator returns null before it loads a
dictionary. Making them nullable would ripple through every generator
call site.

## Related Issues

- Fixes #4439

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.

The "no new warnings" box covers net10.0 and net48: full non-incremental
builds of `UA.slnx`, `tools/SourceGeneration.slnx`,
`tools/MigrationAnalyzer.slnx` and the Aot test projects finished with 0
warnings and 0 errors under the repository's warnings-as-errors
settings. net9.0 and net8.0 also had no nullable diagnostics, but they
were not rebuilt after the final fixes. Tests have not been run locally
yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 08:48:13 +02:00

836 lines
34 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using Moq;
using NUnit.Framework;
using Opc.Ua.Tests;
namespace Opc.Ua.Server.Tests
{
[TestFixture]
[Category("Aggregators")]
[SetCulture("en-us")]
[SetUICulture("en-us")]
[Parallelizable]
public class AggregatorsTests
{
private ITelemetryContext m_telemetry;
private AggregateConfiguration m_configuration;
[SetUp]
public void SetUp()
{
m_telemetry = NUnitTelemetryContext.Create();
m_configuration = new AggregateConfiguration
{
TreatUncertainAsBad = false,
PercentDataBad = 100,
PercentDataGood = 100,
UseSlopedExtrapolation = false
};
}
[Test]
public void GetDefaultConfigurationTreatsUncertainAsBadByDefault()
{
var server = new Mock<IServerInternal>();
using var manager = new AggregateManager(server.Object);
AggregateConfiguration config = manager.GetDefaultConfiguration(default);
// Part 13 v1.05.07 §4.2.1.2: the TreatUncertainAsBad default is True.
Assert.That(config.TreatUncertainAsBad, Is.True);
Assert.That(config.PercentDataBad, Is.EqualTo(100));
Assert.That(config.PercentDataGood, Is.EqualTo(100));
Assert.That(config.UseSlopedExtrapolation, Is.False);
}
[Test]
public void GetNameForStandardAggregateReturnsNameForInterpolative()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Interpolative);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Interpolative)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForAverage()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Average);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Average)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForMinimum()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Minimum);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Minimum)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForMaximum()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Maximum);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Maximum)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForCount()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Count);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Count)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForStart()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Start);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Start)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForStdDevPopulation()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_StandardDeviationPopulation);
Assert.That(name, Is.EqualTo(
QualifiedName.From(BrowseNames.AggregateFunction_StandardDeviationPopulation)));
}
[Test]
public void GetNameForStandardAggregateReturnsDefaultForUnknownId()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(new NodeId(999999));
Assert.That(name, Is.Default);
}
[Test]
public void GetIdForStandardAggregateReturnsIdForAverage()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_Average));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_Average));
}
[Test]
public void GetIdForStandardAggregateReturnsIdForMinimum()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_Minimum));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_Minimum));
}
[Test]
public void GetIdForStandardAggregateReturnsIdForCount()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_Count));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_Count));
}
[Test]
public void GetIdForStandardAggregateReturnsIdForStart()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_Start));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_Start));
}
[Test]
public void GetIdForStandardAggregateReturnsIdForStdDevPopulation()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_StandardDeviationPopulation));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_StandardDeviationPopulation));
}
[Test]
public void GetIdForStandardAggregateReturnsDefaultForUnknownName()
{
NodeId id = Aggregators.GetIdForStandardAggregate(new QualifiedName("NonExistentAggregate"));
Assert.That(id, Is.Default);
}
[Test]
public void CreateStandardCalculatorReturnsCalculatorForInterpolative()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Interpolative,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<AggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsAverageCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Average,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<AverageAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsTimeAverageCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_TimeAverage,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<AverageAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsTimeAverage2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_TimeAverage2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<AverageAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsTotalCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Total,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<AverageAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsTotal2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Total2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<AverageAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMinMaxCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Minimum,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsCountCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Count,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<CountAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsStartEndCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Start,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StartEndAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsStdDevCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_StandardDeviationPopulation,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StdDevAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsStatusCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_DurationGood,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StatusAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsNullForUnknownId()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
new NodeId(999999),
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Null);
}
[Test]
public void CreateStandardCalculatorReturnsAnnotationCountCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_AnnotationCount,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<CountAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsDurationInStateZeroCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_DurationInStateZero,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<CountAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsNumberOfTransitionsCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_NumberOfTransitions,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<CountAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsDeltaCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Delta,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StartEndAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsDeltaBoundsCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_DeltaBounds,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StartEndAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsVariancePopulationCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_VariancePopulation,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StdDevAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsVarianceSampleCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_VarianceSample,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StdDevAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsStdDevSampleCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_StandardDeviationSample,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StdDevAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsWorstQualityCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_WorstQuality,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StatusAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsWorstQuality2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_WorstQuality2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StatusAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsPercentGoodCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_PercentGood,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StatusAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsPercentBadCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_PercentBad,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StatusAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsDurationBadCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_DurationBad,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StatusAggregateCalculator>());
}
[Test]
public void GetNameForStandardAggregateReturnsNameForEnd()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_End);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_End)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForDelta()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Delta);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Delta)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForRange()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Range);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Range)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForTotal()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_Total);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_Total)));
}
[Test]
public void GetNameForStandardAggregateReturnsNameForTimeAverage()
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(
ObjectIds.AggregateFunction_TimeAverage);
Assert.That(name, Is.EqualTo(QualifiedName.From(BrowseNames.AggregateFunction_TimeAverage)));
}
[Test]
public void GetIdForStandardAggregateReturnsIdForEnd()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_End));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_End));
}
[Test]
public void GetIdForStandardAggregateReturnsIdForDelta()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_Delta));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_Delta));
}
[Test]
public void GetIdForStandardAggregateReturnsIdForRange()
{
NodeId id = Aggregators.GetIdForStandardAggregate(
QualifiedName.From(BrowseNames.AggregateFunction_Range));
Assert.That(id, Is.EqualTo(ObjectIds.AggregateFunction_Range));
}
[Test]
public void CreateStandardCalculatorReturnsEndBoundCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_EndBound,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StartEndAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsStartBoundCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_StartBound,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StartEndAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsDurationInStateNonZeroCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_DurationInStateNonZero,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<CountAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMinimum2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Minimum2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMaximum2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Maximum2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsRange2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Range2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMinimumActualTime2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_MinimumActualTime2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMaximumActualTime2Calculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_MaximumActualTime2,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void GetNameAndIdAreConsistentForAllMappings()
{
NodeId[] aggregateIds =
[
ObjectIds.AggregateFunction_Interpolative,
ObjectIds.AggregateFunction_Average,
ObjectIds.AggregateFunction_TimeAverage,
ObjectIds.AggregateFunction_TimeAverage2,
ObjectIds.AggregateFunction_Total,
ObjectIds.AggregateFunction_Total2,
ObjectIds.AggregateFunction_Minimum,
ObjectIds.AggregateFunction_Maximum,
ObjectIds.AggregateFunction_Count,
ObjectIds.AggregateFunction_Start,
ObjectIds.AggregateFunction_End,
ObjectIds.AggregateFunction_Delta,
ObjectIds.AggregateFunction_StandardDeviationPopulation,
ObjectIds.AggregateFunction_VariancePopulation,
ObjectIds.AggregateFunction_StandardDeviationSample,
ObjectIds.AggregateFunction_VarianceSample,
ObjectIds.AggregateFunction_DurationGood,
ObjectIds.AggregateFunction_DurationBad,
ObjectIds.AggregateFunction_PercentGood,
ObjectIds.AggregateFunction_PercentBad,
ObjectIds.AggregateFunction_WorstQuality,
ObjectIds.AggregateFunction_WorstQuality2
];
foreach (NodeId aggregateId in aggregateIds)
{
QualifiedName name = Aggregators.GetNameForStandardAggregate(aggregateId);
Assert.That(name, Is.Not.Default,
$"Name should be found for aggregate {aggregateId}");
NodeId roundTrippedId = Aggregators.GetIdForStandardAggregate(name);
Assert.That(roundTrippedId, Is.EqualTo(aggregateId),
$"Round-tripped id should match for aggregate {aggregateId}");
}
}
[Test]
public void CreateStandardCalculatorWithSteppedFlagReturnsCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Average,
startTime, endTime, 10000, true, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<AverageAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsEndCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_End,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StartEndAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsDurationGoodCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_DurationGood,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<StatusAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMaximumActualTimeCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_MaximumActualTime,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMinimumActualTimeCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_MinimumActualTime,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
[Test]
public void CreateStandardCalculatorReturnsMaximumCalculator()
{
var startTime = new DateTimeUtc(2024, 1, 1, 0, 0, 0);
DateTimeUtc endTime = startTime.AddMilliseconds(10000);
IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
ObjectIds.AggregateFunction_Maximum,
startTime, endTime, 10000, false, m_configuration, m_telemetry)!;
Assert.That(calculator, Is.Not.Null);
Assert.That(calculator, Is.InstanceOf<MinMaxAggregateCalculator>());
}
}
}