Files
DP44/enriched-qwen3-coder-next/DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestSummaryList/Model.md
2026-04-17 14:55:32 -04:00

103 lines
5.8 KiB
Markdown

---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestSummaryList/Model/TestSummaryModel.cs
generated_at: "2026-04-16T13:55:21.942566+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "eacbbab8741bd493"
---
# Documentation: TestSummaryModel.cs
## 1. Purpose
`TestSummaryModel` is a model class within the `DTS.Viewer.TestSummaryList` module responsible for loading and managing test summary data from `.dts` files. It implements `IBaseModel` and serves as the data access layer between the file system and the `ITestSummaryListViewModel`, handling asynchronous test metadata retrieval, list merging logic, and test selection state management. The class coordinates UI busy states and publishes application-wide events via Prism's `IEventAggregator`.
---
## 2. Public Interface
### Properties
| Name | Type | Description |
|------|------|-------------|
| `Parent` | `ITestSummaryListViewModel` | Reference to the parent ViewModel. Settable property. |
| `_eventAggregator` | `IEventAggregator` | Prism event aggregator for publishing/subscribing to application events. Settable property. |
| `IsSaved` | `bool` | Get-only property. **Note:** Appears unassigned in source (ReSharper suppression present). |
| `PropertyChanged` | `PropertyChangedEventHandler` | Event raised when a property value changes. |
### Methods
#### `void GetTestSummary(string path, string file, bool Include = false, bool selectAll = false)`
Loads test definitions from the specified data folder asynchronously.
- **Parameters:**
- `path` - Directory path to the data folder. Will be created if it doesn't exist.
- `file` - The `.dts` file to load.
- `Include` - When `true` and list has multiple items, selects the first test in the list.
- `selectAll` - When `true`, selects all tests; otherwise uses default selection logic.
- **Behavior:**
- Sets `Parent.IsBusy = true` and publishes `BusyIndicatorChangeNotification(true)`.
- Publishes `AppStatusExEvent` with `AppStatusArg.Busy`.
- Creates the directory at `path` if it doesn't exist.
- Delegates to `TestMetadataList.GetTestSummaryListAsync()` to retrieve test summaries.
- Merges results into `Parent.TestSummaryList`, preserving existing selection state for duplicate tests.
- Calls `DetermineTestsSelected(selectAll)` to apply selection logic.
- Publishes `TestLoadedCountNotification` with loaded count and parent ViewModel reference.
- Publishes `BusyIndicatorChangeNotification(false)` and sets `Parent.IsBusy = false` on completion.
#### `void OnPropertyChanged(string propertyName)`
Raises the `PropertyChanged` event for the specified property name.
---
## 3. Invariants
1. **Directory Creation:** If `path` is non-empty and the directory doesn't exist, it will be created before loading tests.
2. **Test Uniqueness:** Tests are uniquely identified by the combination of `Id`, `SetupName`, and `DataType`. When a duplicate is detected, the existing test is replaced at its original index while preserving its `IsSelected` state.
3. **Selection Guarantees:**
- If `selectAll` is `true`, all tests in `Parent.TestSummaryList` will have `IsSelected = true`.
- If `selectAll` is `false` and the list contains exactly one test, that test is selected.
- If `selectAll` is `false`, the list has multiple tests, and all tests share the same setup name with at least one `DataType == "ALL"`, the first test is selected.
4. **Event Pairing:** `BusyIndicatorChangeNotification` and `AppStatusExEvent` are always published in pairs (busy/available) even in exception scenarios via the `finally` block.
---
## 4. Dependencies
### This Module Depends On:
- `DTS.Common.Classes.Viewer.TestMetadata.TestMetadataList` - Provides `GetTestSummaryListAsync()` method.
- `DTS.Common.Base.IBaseModel` - Interface implemented by this class.
- `DTS.Common.Events` - Event types: `BusyIndicatorChangeNotification`, `AppStatusExEvent`, `TestLoadedCountNotification`.
- `DTS.Common.Interface` - Likely defines `ITestSummaryListViewModel` (inferred).
- `DTS.Viewer.TestSummaryList.ViewModel` - `ITestSummaryListViewModel`, `TestSummaryViewListModel`.
- `Prism.Events.IEventAggregator` - Event aggregation pattern.
- `System.Windows.Threading.Dispatcher` - For async UI dispatching.
### Event Types Referenced:
- `BusyIndicatorChangeNotification` - Payload: `bool`
- `AppStatusExEvent` - Payload: `AppStatusExArg`
- `TestLoadedCountNotification` - Payload: `TestLoadedCountNotificationArg`
- `AppStatusArg` - Enum with `Busy` and `Available` members.
---
## 5. Gotchas
1. **Unassigned Property:** `IsSaved` is a get-only auto-property with no visible assignment. The ReSharper comment `// ReSharper disable UnassignedGetOnlyAutoProperty` indicates this is a known issue. Behavior is undefined.
2. **Naming Convention Violation:** `_eventAggregator` is a public property prefixed with an underscore, which violates typical C# naming conventions for public members.
3. **Nested Try-Catch with Silent Failure:** The inner try-catch block (lines 83-92) silently swallows all exceptions. The comment indicates this was added for a regression build to prevent crashes from a new feature (case 16158).
4. **Async Void Lambda:** The `InvokeAsync` uses an `async` lambda, but the outer method returns `void`. Exception handling is done inside the lambda, but any unhandled exceptions before the first `await` could be problematic.
5. **Collection Event Subscription:** When `Parent.TestSummaryList` is empty, the new list is assigned directly with `CollectionChanged` subscription. When non-empty, items are added individually without apparent `CollectionChanged` subscription on individual items.
6. **Historical Bug Fixes:** Multiple manuscript case references in comments (28164, 35546, 16158) indicate this class has accumulated patches for specific edge cases around test selection and identification logic.