5.6 KiB
5.6 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T03:49:48.727573+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | ae00661176117a50 |
StateMachine.Tests
Documentation Page: States Class (StateMachine Module)
1. Purpose
The States class serves as a singleton registry and factory for all known DAS (Data Acquisition System) state objects, ensuring consistent access to state instances and enabling centralized configuration of shared dependencies (e.g., IDASFactory). It abstracts the instantiation and management of state objects—each corresponding to a value in the State enum—so that other parts of the system can retrieve fully initialized, type-safe state representations without duplicating construction logic or state-specific dependencies.
2. Public Interface
public static States Instance { get; }
- Type: Static read-only property
- Behavior: Returns the singleton instance of
States. Guaranteed to be non-null and identical across all calls (verified byInstance_ShouldBeSametest).
public static void SetDASFactory(IDASFactory factory)
- Behavior: Assigns the provided
IDASFactoryinstance to all state objects managed byStates. After calling this, every state retrieved viaGetIDASState(...)will have itsDASFactoryproperty set to the provided factory. - Note: Must be called before states are accessed (or at least before
GetIDASStateis invoked), as state objects are lazily initialized and only receive the factory upon first access (inferred from testSetDASFactory_ShouldSetToAnInstanceOfDASFactory).
public IDASState GetIDASState(State state)
- Parameters:
state: A value from theStateenum (e.g.,State.Arm,State.Realtime).
- Returns: An
IDASStateinstance corresponding to the requestedState. - Behavior:
- Returns a state object whose
Stateproperty matches the inputstate. - Throws
InvalidOperationExceptionwith message"Undefined State"if passed aStatevalue not defined in theStateenum (e.g.,(State)45). - The returned
IDASStatewill have itsDASFactoryproperty set ifSetDASFactorywas previously called.
- Returns a state object whose
public DASState Arm { get; }
public DASState Arming { get; }
public DASState Configure { get; }
public DASState ConfigureStart { get; }
public DASState Diagnose { get; }
public DASState Download { get; }
public DASState HardwareDiscovery { get; }
public DASState HardwareDiscoveryStart { get; }
public DASState Prepare { get; }
public DASState Realtime { get; }
public DASState RealtimeStart { get; }
- Type: Read-only properties (return type inferred as
DASState, a concrete implementation ofIDASState). - Behavior: Each property exposes a pre-instantiated state object corresponding to its name (e.g.,
Armreturns theDASStateforState.Arm). All are non-null and initialized with their respectiveStateenum value.
3. Invariants
- Singleton Consistency:
States.Instancealways returns the same object reference. - State Completeness: For every defined
Stateenum value,States.Instance.GetIDASState(state)returns a validIDASStatewithState == state. - Factory Propagation: After
SetDASFactory(factory)is called, all states returned byGetIDASState(...)(and exposed via named properties likeArm,Realtime, etc.) must haveDASFactory == factory. - Enum Validity Enforcement:
GetIDASState(...)rejects anyStatevalue not present in theStateenum viaInvalidOperationException. - Non-null States: All state properties (
Arm,Arming, etc.) and results fromGetIDASState(...)are non-null.
4. Dependencies
Depends on
DTS.DASLib.Service.StateMachinenamespace (containsStates,IDASState,DASState,Stateenum).DTS.Common.Interface.DASFactorynamespace (containsIDASFactory).NUnit.Framework(for test assertions).NSubstitute(for mockingIDASFactoryin tests).
Depended on by
StateMachine.Tests(this file), which validatesStatesbehavior.- Inferred: Other modules in
DTS.DASLib.Service.StateMachine(and possibly higher-level services) rely onStatesto obtain state objects.
5. Gotchas
- Factory Initialization Timing:
SetDASFactorymust be called before accessing state objects viaGetIDASState(...)or named properties (e.g.,States.Instance.Arm), otherwise states may be initialized with anullDASFactory. - Lazy Initialization: State objects are not pre-instantiated at
Instanceconstruction; they are created on first access (e.g., whenArmorGetIDASState(State.Arm)is called), and only then receive the factory ifSetDASFactoryhas been called. - No Explicit State Transition Logic: This module only manages state instances and their shared dependencies. It does not define state transitions, guards, or event handling (those are likely elsewhere in the
StateMachinenamespace). - Test Interdependence: The
SetDASFactory_ShouldSetToAnInstanceOfDASFactorytest assumesGetIDASStateworks correctly (see inline comment). IfGetIDASStatefails, this test’s failure mode is ambiguous. - Undefined State Handling: Passing an invalid
Stateenum value (e.g., via cast(State)45) throwsInvalidOperationException—notArgumentOutOfRangeException—despite the input being an enum value.
None identified beyond the above.