Files
DP44/enriched-qwen3-coder-next/DataPRO/UnitTest/DTS.Common.Import.Tests.md
2026-04-17 14:55:32 -04:00

7.2 KiB
Raw Permalink Blame History

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/UnitTest/DTS.Common.Import.Tests/GroupHelperShould.cs
DataPRO/UnitTest/DTS.Common.Import.Tests/CalibrationImportShould.cs
2026-04-16T03:51:24.502617+00:00 Qwen/Qwen3-Coder-Next-FP8 1 91da420b0b2120ea

DTS.Common.Import.Tests

Documentation: DTS.Common.Import.Tests Unit Test Module


1. Purpose

This module contains unit tests for the DTS.Common.Import functionality, specifically validating the behavior of GroupHelper and CalibrationImport classes. Its role is to ensure correctness, robustness, and invariants of data import logic—particularly around group creation, channel ordering, sensor ID normalization, and calibration record handling—including edge cases such as null inputs and excitation voltage mismatches. It does not contain production logic itself but serves as the authoritative specification for expected behavior of the tested components.


2. Public Interface

The test file itself does not expose a public API; it tests public members of other modules. Based on test usage, the following public APIs are referenced:

GroupHelper.CreateEmptyGroup()

  • Signature: static Group CreateEmptyGroup() (inferred from usage)
  • Behavior: Creates a new Group instance with LastModifiedBy initialized to "---".

GroupHelper.ReverseChannelOrder(TestTemplate, Dictionary<string, string>, List<SensorData>)

  • Signature: static List<T> ReverseChannelOrder<T>(TestTemplate testTemplate, Dictionary<string, string> channelMap, List<SensorData> sensors) (inferred from usage)
  • Behavior: Safely handles null inputs for testTemplate and sensors by returning an empty list. Otherwise, performs channel reordering based on channelMap. (Exact implementation details not visible.)

GroupHelper.NormalizeSensorIds(List<SensorData>)

  • Signature: static List<SensorData> NormalizeSensorIds(List<SensorData> sensors) (inferred from usage)
  • Behavior: Safely handles null input by returning an empty list. Otherwise, normalizes sensor IDs in the list. (Exact normalization logic not visible.)

CalibrationImport.CheckForExcitationCalibration(SensorCalibration, int, ExcitationVoltageOptions.ExcitationVoltageOption, string)

  • Signature: SensorCalibration CheckForExcitationCalibration(SensorCalibration sensorCalibration, int channelIndex, ExcitationVoltageOptions.ExcitationVoltageOption expectedExcitation, string channelName)
  • Behavior:
    • If the excitation voltage of the first calibration record matches expectedExcitation, returns the original sensorCalibration unchanged.
    • If it does not match, returns a modified SensorCalibration with an additional calibration record (resulting in Records.Records.Count == 2). (Exact record duplication or cloning logic not visible.)

CalibrationImport.AddLinearCalRecordIfNeeded(SensorCalibration, bool, bool)

  • Signature: SensorCalibration AddLinearCalRecordIfNeeded(SensorCalibration sensorCalibration, bool forceAdd, bool isZeroMethodRequired) (inferred from usage)
  • Behavior:
    • If sensorCalibration.Records.Records.Count != 1, returns the original unchanged.
    • If Count == 1, returns a modified SensorCalibration where:
      • The existing records Poly.IsValid is set to false.
      • A second calibration record is added (resulting in Count == 2).
        (Exact record creation logic not visible.)

CalibrationImport.AddLinearZeroMethodIfNeeded(SensorCalibration, ZeroMethodType, int, int)

  • Signature: SensorCalibration AddLinearZeroMethodIfNeeded(SensorCalibration sensorCalibration, ZeroMethodType zeroMethodType, int channelIndex, int sensorIndex) (inferred from usage)
  • Behavior:
    • If sensorCalibration.Records.Records.Count != 1, returns the original unchanged.
    • If Count == 1, returns a modified SensorCalibration with ZeroMethods.Methods.Count == 2. (Exact zero method addition logic not visible.)

3. Invariants

  • GroupHelper.CreateEmptyGroup() always produces a Group with LastModifiedBy == "---".
  • GroupHelper.ReverseChannelOrder() and GroupHelper.NormalizeSensorIds() must never throw exceptions when passed null for sensors or testTemplate; they must return empty lists instead.
  • CalibrationImport.CheckForExcitationCalibration():
    • When the first calibration records Excitation matches the expected value, the returned object is identical (reference equality not tested, but no modification is performed).
    • When mismatched, the returned SensorCalibration has exactly two calibration records.
  • CalibrationImport.AddLinearCalRecordIfNeeded():
    • Only modifies the calibration when there is exactly one record.
    • In that case, it invalidates the existing record (Poly.IsValid == false) and adds a second record.
  • CalibrationImport.AddLinearZeroMethodIfNeeded():
    • Only modifies the calibration when there is exactly one record.
    • In that case, it ensures ZeroMethods.Methods.Count == 2.

4. Dependencies

Test Module Dependencies:

  • DTS.Common.Import.Tests references:
    • DTS.Common.Interface.TestSetups.TestSetupsList (for TestTemplate, inferred)
    • DTS.SensorDB (for SensorData)
    • DataPROWin7.DataModel (for Group, inferred)
    • NUnit.Framework (test framework)
    • NSubstitute (mocking library)
    • DTS.Common.Enums (for ExcitationVoltageOptions, ZeroMethodType)
    • DTS.Common.Interface.Sensors (for ICalibrationRecords, ICalibrationRecord)
    • Classes.Sensors.LinearizationFormula (from DTS.SensorDB or DataPROWin7.DataModel, inferred)

Tested Components Dependencies (inferred):

  • GroupHelper, CalibrationImport likely depend on:
    • DTS.SensorDB (sensor data models)
    • DTS.Common.Interface.Sensors (calibration interfaces)
    • DTS.Common.Enums (enum types)
    • Possibly DataPROWin7.DataModel (e.g., Group, TestTemplate)

Dependents:

  • This test module is consumed by the test runner (NUnit) and likely part of a CI pipeline. No runtime dependents are visible.

5. Gotchas

  • Typos in test names: Tests use "ShouldNotThorwException" (missing 'w' in "Throw")—likely a typo in test method names, but does not affect behavior.
  • Ambiguity in record duplication logic: In CheckForExcitationCalibration, when excitation mismatches, a second record is added—but it is unclear whether this is a copy of the first record, a new placeholder, or a modified record. The tests only assert count, not content.
  • Zero method vs. calibration record distinction: AddLinearZeroMethodIfNeeded modifies ZeroMethods.Methods, while AddLinearCalRecordIfNeeded modifies Records.Records. The interaction between these two mechanisms is not tested—potential for confusion or overlap.
  • No tests for AddLinearCalRecordIfNeeded with forceAdd == true or isZeroMethodRequired == true: Only default (false, false) cases are tested.
  • No tests for non-null, non-empty inputs in GroupHelper methods: All tests for ReverseChannelOrder and NormalizeSensorIds only verify null-safety; behavior on valid inputs is not specified here.

No other obvious tech debt or quirks identified from source alone.