init
This commit is contained in:
21
docs/ai/DataPRO/UnitTest/DTS.Common.DataModel.Tests.md
Normal file
21
docs/ai/DataPRO/UnitTest/DTS.Common.DataModel.Tests.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DTS.Common.DataModel.Tests/GroupShould.cs
|
||||
generated_at: "2026-04-17T16:10:42.606123+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "3fde041bb830365d"
|
||||
---
|
||||
|
||||
# DTS.Common.DataModel.Tests
|
||||
|
||||
### Purpose
|
||||
This module is a unit test assembly that validates the behavior of the `Group` class from the `GroupList.Model` namespace. It exists to ensure the correctness of filtering logic and state transitions within the data model layer, specifically testing the `Filter` method's string matching across multiple properties and the `ConvertToEmbedded` method's idempotency.
|
||||
|
||||
### Public Interface
|
||||
|
||||
**Class: `GroupShould`** (NUnit TestFixture)
|
||||
- `void Filter_ShouldReturnTrueOnEmptyTerm()` — Verifies that `Group.Filter("")` returns `true`.
|
||||
- `void Filter_ShouldReturnTrueOnNullTerm()` — Verifies that `Group.Filter(null)` returns `true`.
|
||||
- `void Filter_ShouldReturnTrueWhenAssociatedTestSetupsIsNull()` — Verifies that `Filter` returns `true` when `AssociatedTestSetups` is null, regardless of search term.
|
||||
- `void Filter_ShouldReturnTrueWhenfindTerm()`
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DTS.Common.DataModel.Tests/Properties/AssemblyInfo.cs
|
||||
generated_at: "2026-04-17T16:52:48.678786+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "a62008456f892e2b"
|
||||
---
|
||||
|
||||
# Documentation for AssemblyInfo.cs
|
||||
|
||||
## 1. Purpose
|
||||
This file provides assembly-level metadata and configuration attributes for the `DTS.Common.DataModel.Tests` assembly. It exists to embed identifying information—such as title, version, and copyright—into the compiled test DLL, and to configure COM visibility settings. Its role is strictly limited to build-time configuration; it contains no executable application logic.
|
||||
|
||||
## 2. Public
|
||||
35
docs/ai/DataPRO/UnitTest/DTS.Common.Import.Tests.md
Normal file
35
docs/ai/DataPRO/UnitTest/DTS.Common.Import.Tests.md
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DTS.Common.Import.Tests/GroupHelperShould.cs
|
||||
- DataPRO/UnitTest/DTS.Common.Import.Tests/CalibrationImportShould.cs
|
||||
generated_at: "2026-04-17T16:55:20.709240+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "58c14f397587ec7e"
|
||||
---
|
||||
|
||||
# Documentation: DTS.Common.Import Tests
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module contains unit tests for the `GroupHelper` and `CalibrationImport` classes within the `DTS.Common.Import` namespace. The tests verify null-safety handling, group creation behavior, and calibration record manipulation logic. These tests serve as both verification and implicit documentation of the expected behaviors of the production classes under test.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### `GroupHelper` (Static class, inferred from usage)
|
||||
|
||||
| Method | Signature | Behavior |
|
||||
|--------|-----------|----------|
|
||||
| `CreateEmptyGroup` | `CreateEmptyGroup()` → Returns an object with `LastModifiedBy` property | Creates a new group instance with `LastModifiedBy` initialized to `"---"`. |
|
||||
| `ReverseChannelOrder` | `ReverseChannelOrder(TestTemplate, Dictionary<string, string>, List<SensorData>)` → Returns a collection | Reverses channel order based on a test template, channel mapping dictionary, and sensor list. Returns an empty collection (count 0) when `TestTemplate` is null or sensors list is null. |
|
||||
| `NormalizeSensorIds` | `NormalizeSensorIds(List<SensorData>)` → Returns a collection | Normalizes sensor IDs. Returns an empty collection (count 0) when input list is null. |
|
||||
|
||||
### `CalibrationImport` (Instantiable class)
|
||||
|
||||
| Method | Signature | Behavior |
|
||||
|--------|-----------|----------|
|
||||
| `CheckForExcitationCalibration` | `CheckForExcitationCalibration(SensorCalibration, int, ExcitationVoltageOption, string)` → Returns `SensorCalibration` | Checks if a calibration record exists with matching excitation voltage. Returns the same `SensorCalibration` if excitation matches; otherwise adds a new record to `Records.Records` (resulting in count of 2 when starting with 1 non-matching record). |
|
||||
| `AddLinearCalRecordIfNeeded` | `AddLinearCalRecordIfNeeded(SensorCalibration, bool, bool)` → Returns `SensorCalibration` | Adds a linear calibration record if the input `Records.Records` count is exactly 1. When count is not 1, returns the same object unchanged. When count is 1, adds a second record with `Poly.IsValid = false`. |
|
||||
| `AddLinearZeroMethodIfNeeded` | `AddLinearZeroMethodIfNeeded(SensorCalibration, ZeroMethodType, int, int)` → Returns `SensorCalibration` | Adds zero methods if `Records.Records` count is
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DTS.Common.Import.Tests/Properties/AssemblyInfo.cs
|
||||
generated_at: "2026-04-17T16:44:47.643312+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "50a9c044b8a487aa"
|
||||
---
|
||||
|
||||
# Documentation: AssemblyInfo.cs (DTS.Common.Import.Tests)
|
||||
|
||||
## 1. Purpose
|
||||
This file provides assembly-level metadata and configuration for the `DTS.Common.Import.Tests` assembly. It exists to embed identifying information—such as title, version,
|
||||
196
docs/ai/DataPRO/UnitTest/DatabaseUnitTesting.md
Normal file
196
docs/ai/DataPRO/UnitTest/DatabaseUnitTesting.md
Normal file
@@ -0,0 +1,196 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DefaultPropertiesTests.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/LaboratoryDetailsTests.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/TestSetups.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/ResultSetTester.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DASTests.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/CustomerDetailsTests.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DASChannelsTests.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/CalculatedChannelsTests.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DBAPITests.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsRegionsOfInterest.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DatabaseModificationTester.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsChannels.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsSensorsAnalog.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsGroupHardware.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsCustomerDetails.cs
|
||||
generated_at: "2026-04-17T15:44:53.502112+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "89b12019c46b65c4"
|
||||
---
|
||||
|
||||
# Database Unit Testing Module Documentation
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides a unit testing framework for validating database operations in the DataPRO system. It enables testing of stored procedures, database modifications, and API operations against a SQL Server database. The framework uses database snapshots for test isolation, transaction rollback for cleanup, and XML-based result comparison for verifying database state changes. It tests various domain entities including DAS (Data Acquisition Systems), channels, sensors, customer details, laboratory details, and regions of interest.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### TestSetups (Base Class)
|
||||
**File:** `TestSetups.cs`
|
||||
|
||||
Base class providing test infrastructure for database unit tests.
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `TFSetup` | `void TFSetup()` | One-time setup marked with `[OneTimeSetUp]`. Creates database snapshot via `DatabaseModificationTester` constructor. |
|
||||
| `TFTearDown` | `void TFTearDown()` | One-time teardown marked with `[OneTimeTearDown]`. Disposes `DatabaseModificationTester` (drops snapshot) and closes connection. |
|
||||
| `SetUp` | `void SetUp()` | Per-test setup marked with `[SetUp]`. Begins a test transaction via `_unitTests.BeginTestTransaction()`. |
|
||||
| `TearDown` | `void TearDown()` | Per-test teardown marked with `[TearDown]`. Ends test transaction via `_unitTests.EndTestTransaction()`. |
|
||||
| `TestResultPath` | `String TestResultPath { get; }` | Returns `_testResultsInitialPath` pointing to `TestResults\` directory. |
|
||||
| `UnitTests` | `DatabaseModificationTester UnitTests { get; }` | Returns the `DatabaseModificationTester` instance. |
|
||||
| `BSETUPMODE` | `bool BSETUPMODE { get; }` | Returns constant `_BSETUPMODE` (always `false`). |
|
||||
| `Command` | `SqlCommand Command { get; }` | Returns the current test's `SqlCommand` associated with the transaction. |
|
||||
|
||||
### DatabaseModificationTester
|
||||
**File:** `DatabaseModificationTester.cs`
|
||||
|
||||
Core class for managing database snapshots and transaction-based testing. Implements `IDisposable`.
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| Constructor | `DatabaseModificationTester(SqlConnection connection, string databaseName, string snapshotName)` | Creates a database snapshot via `DatabaseAdapter.CreateSnapshot()`. Sets `_activeSnapshot = true`. |
|
||||
| `BeginTestTransaction` | `SqlTransaction BeginTestTransaction()` | Begins a new SQL transaction. Ends any existing transaction first. Returns the transaction. |
|
||||
| `EndTestTransaction` | `void EndTestTransaction()` | Calls `_dataComparer.CleanUp()`, rolls back and disposes the transaction. Throws `InvalidOperationException` if no transaction exists. |
|
||||
| `WriteDiffsToXml` | `void WriteDiffsToXml(string filename)` | Writes database differences between current state and snapshot to XML file via `XmlFileAdapter.Write()`. |
|
||||
| `CompareDiffsToXml` | `bool CompareDiffsToXml(string filename)` | Compares current differences against stored XML file. Returns `true` if equal. |
|
||||
| `AreEqual` | `bool AreEqual()` | Returns `true` if `GenerateDifferences().TableCount == 0`. |
|
||||
| `AddColumnToIgnore` | `void AddColumnToIgnore(string schemaName, string objectName, string columnName)` | Adds a single column to ignore during comparison. |
|
||||
| `AddColumnsToIgnore` | `void AddColumnsToIgnore(string schema1, string name1, List<string> columnNames)` | Adds multiple columns to ignore during comparison. |
|
||||
| `AddObjectComparison` | `void AddObjectComparison(string schemaName, string tableName)` | Adds an object for comparison. |
|
||||
| `Dispose` | `void Dispose()` | Drops the database snapshot if `_activeSnapshot` is true. |
|
||||
|
||||
### ResultSetTester
|
||||
**File:** `ResultSetTester.cs`
|
||||
|
||||
Utility for testing stored procedure result sets.
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| Constructor | `ResultSetTester(SqlConnection connection, string procedureName)` | Creates `SqlCommand` with `CommandType.StoredProcedure`. |
|
||||
| Constructor | `ResultSetTester(SqlCommand command)` | Wraps an existing `SqlCommand`. |
|
||||
| `PrintOuputParameterValues` | `IEnumerable<KeyValuePair<string, object>> PrintOuputParameterValues()` | Returns output parameters as key-value pairs. |
|
||||
| `CompareToFile` | `bool CompareToFile(string filename)` | Parses command results via `ResultSetParser.Parse()`, reads expected from XML via `XmlFileAdapter.Read()`, compares for equality. |
|
||||
| `OutputToFile` | `void OutputToFile(string filename)` | Parses results and writes to XML file. |
|
||||
| `SetInputParameter` | `void SetInputParameter(string parameterName, object parameterValue)` | Sets or adds an input parameter. Uses `Parameters.AddWithValue()` if not present. |
|
||||
| `SetOutputParameter` | `void SetOutputParameter(string parameterName, SqlDbType type, int size)` | Configures an output parameter. Removes existing parameter if present. Sets `Size` if non-zero. |
|
||||
|
||||
### DBAPITests (Partial Class)
|
||||
**File:** `DBAPITests.cs`, `DbAPITestsChannels.cs`, `DbAPITestsCustomerDetails.cs`, `DbAPITestsGroupHardware.cs`, `DbAPITestsRegionsOfInterest.cs`, `DbAPITestsSensorsAnalog.cs`
|
||||
|
||||
Main test fixture for database API operations.
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `Setup` | `void Setup()` | `[OneTimeSetUp]` Initializes logger, configures `ConnectionDetails`, calls `DbAPI.DbAPI.Connections.ConnectToDb()`. |
|
||||
| `TestConnect` | `void TestConnect()` | Verifies active connections exist via `GetActiveConnections().Any()`. |
|
||||
| `TestLogin` | `void TestLogin()` | Logs in as "Admin" with password "DTSAdmin" via `LoginUser()`. |
|
||||
| `Login` | `void Login()` | Private helper that performs login and sets `_user` and `clientDbVersion`. |
|
||||
| `RegionsOfInterest` | `void RegionsOfInterest()` | Tests ROI operations for database version 92+. Tests `TestSetupsUpdateInsert`, `RegionsOfInterestInsert`, `RegionsOfInterestGet`, `RegionsOfInterestDelete`. |
|
||||
| `TestChannelsInsert/Update/Get/Delete` | `void TestChannels*()` | Tests channel CRUD operations via `DbAPI.DbAPI.Channels.*` methods. |
|
||||
| `TestSensorsDeleteAll` | `void TestSensorsDeleteAll()` | Tests `SensorsDeleteAll` preserves test-specific sensors (`TEST_SPECIFIC_ANALOG_SERIAL`, `TEST_SPECIFIC_CLOCK_SERIAL`). |
|
||||
| `TestSensorsAnalogInsertAndDelete` | `void TestSensorsAnalogInsertAndDelete()` | Tests analog sensor CRUD via `SensorsAnalogUpdateInsert`, `SensorsAnalogGet`, `SensorsDelete`. |
|
||||
| `TestSensorAnalogInsertAndDeleteShouldFail` | `void TestSensorAnalogInsertAndDeleteShouldFail()` | Verifies operations fail with null user or connection. |
|
||||
| `TestSensorsAnalogBridgeResistanceGet` | `void TestSensorsAnalogBridgeResistanceGet()` | Tests `SensorsAnalogBridgeResistanceGet` returns correct resistance value. |
|
||||
| `TestGroupHardwareInsertGetAndDelete` | `void TestGroupHardwareInsertGetAndDelete()` | Tests `GroupHardwareInsert`, `GroupHardwareGet`, `GroupHardwareDelete`. |
|
||||
| `CustomerDetails` | `void CustomerDetails()` | Tests `CustomerDetailsInsert`, `CustomerDetailsGet`, `CustomerDetailsUpdate`, `CustomerDetailsDelete`. |
|
||||
| `CreateFakeChannel` | `IChannelDbRecord CreateFakeChannel()` | Creates a test `ChannelDbRecord`. |
|
||||
| `CreateFakeSensor` | `IAnalogDbRecord CreateFakeSensor()` | Creates a test `AnalogDbRecord` with `BridgeResistance = 350`. |
|
||||
| `CreateFakeGroup` | `IGroupDbRecord CreateFakeGroup(string displayName, int? staticGroupId)` | Creates a test `GroupDbRecord`. |
|
||||
| `CreateGroupHardwareDbRecord` | `GroupHardwareDbRecord CreateGroupHardwareDbRecord(int groupId, int dasId)` | Creates a test `GroupHardwareDbRecord`. |
|
||||
| `CreateFakeCustomerDetails` | `CustomerDetailsDbRecord CreateFakeCustomerDetails(string name)` | Creates a test `CustomerDetailsDbRecord`. |
|
||||
| `CreateFakeTestSetupWithROIs` | *(referenced but implementation not in provided files)* | Creates test setup with ROIs. |
|
||||
|
||||
### Test Fixture Classes (Commented-Out Tests)
|
||||
**Files:** `DefaultPropertiesTests.cs`, `LaboratoryDetailsTests.cs`, `DASTests.cs`, `CustomerDetailsTests.cs`, `DASChannelsTests.cs`, `CalculatedChannelsTests.cs`
|
||||
|
||||
These classes inherit from `TestSetups` and contain commented-out test stubs documenting intended test cases for various stored procedures:
|
||||
|
||||
- `sp_LabratoryDetailsUpdateInsert`
|
||||
- `sp_DASDelete`, `sp_DASGet`, `sp_DASCUpdateInsert`, `sp_DASInUpdateInsert`
|
||||
- `sp_CustomerDetailsDelete`, `sp_CustomerDetailsGet`, `sp_CustomerDetailsUpdateInsert`, `sp_CustomerDetailsInUpdateInsert`
|
||||
- `sp_DASChannelsDelete`, `sp_DASChannelsGet`, `sp_DASChannelsUpdateInsert`, `sp_DASChannelsInUpdateInsert`
|
||||
- `sp_CalculatedChannelsDelete`, `sp_CalculatedChannelsGet`, `sp_CalculatedChannelsUpdateInsert`, `sp_CalculatedChannelsInUpdateInsert`
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
1. **Transaction Isolation**: Every test runs within a transaction that is rolled back in `TearDown`. This ensures no permanent database modifications from tests.
|
||||
|
||||
2. **Snapshot Lifecycle**: A database snapshot is created in `TFSetup` (via `DatabaseModificationTester` constructor) and must be dropped in `TFTearDown` (via `Dispose()`). The `_activeSnapshot` flag prevents double-drop attempts.
|
||||
|
||||
3. **Single Active Transaction**: `BeginTestTransaction()` will end any existing transaction before creating a new one.
|
||||
|
||||
4. **EndTestTransaction Requires Active Transaction**: Calling `EndTestTransaction()` when `_transaction` is null throws `InvalidOperationException`.
|
||||
|
||||
5. **BSETUPMODE is Always False**: The property returns a constant `false` value.
|
||||
|
||||
6. **CustomerDetails Name Constraint**: Per comments in `CustomerDetailsTests.cs`, "Name cannot be null as that is the identifying field for insert or update."
|
||||
|
||||
7. **DAS Serial Number Requirement**: Per comments in `DASTests.cs`, "DAS must have serial number."
|
||||
|
||||
8. **SensorsDeleteAll Preserves Test Sensors**: `TestSensorsDeleteAll` verifies that `TEST_SPECIFIC_ANALOG_SERIAL` and `TEST_SPECIFIC_CLOCK_SERIAL` sensors remain after delete all.
|
||||
|
||||
9. **ROI Operations Version Gating**: `RegionsOfInterestInsert` should fail (return non-zero HR) for database version ≤ 91.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### This Module Depends On:
|
||||
- **NUnit.Framework** - Test framework (`[TestFixture]`, `[Test]`, `[SetUp]`, `[TearDown]`, `[OneTimeSetUp]`, `[OneTimeTearDown]`, `Assert`)
|
||||
- **System.Data.SqlClient** - SQL Server client (`SqlConnection`, `SqlCommand`, `SqlParameter`, `SqlTransaction`)
|
||||
- **System.Data** - ADO.NET types (`CommandType`, `ParameterDirection`, `SqlDbType`)
|
||||
- **DTS.Common.Interface.Database** - `IUserDbRecord`
|
||||
- **DTS.Common.Interface.Channels** - `IChannelDbRecord`
|
||||
- **DTS.Common.Interface.Sensors** - `IAnalogDbRecord`
|
||||
- **DTS.Common.Interface.Groups** - `IGroupDbRecord`
|
||||
- **DTS.Common.Interface.TestMetaData** - `ICustomerDetailsDbRecord`
|
||||
- **DTS.Common.Interface.TestSetups.TestSetupsList** - Test setup interfaces
|
||||
- **DTS.Common.Classes.Channels** - `ChannelDbRecord`
|
||||
- **DTS.Common.Classes.Sensors** - `AnalogDbRecord`
|
||||
- **DTS.Common.Classes.Groups** - `GroupDbRecord`, `GroupHardwareDbRecord`
|
||||
- **DTS.Common.Classes.Hardware** - Hardware-related classes
|
||||
- **DTS.Common.Classes.CustomerDetails** - `CustomerDetailsDbRecord`
|
||||
- **DTS.Common.Classes.TestSetups** - Test setup classes
|
||||
- **DTS.Common.Enums.Sensors** - Sensor enums
|
||||
- **DTS.Common.Storage** - `DbOperations` (includes `CURRENT_DB_VERSION`, `MINIMUM_LTS_DB_VERSION`)
|
||||
- **DTS.Common.Utils.Database** - `GetSqlServerLocalDbPath()`, `GetODBCToolsPath()`
|
||||
- **DbAPI.DbAPI** - Main API class with nested `Connections`, `TestSetups`, `RegionsOfInterest`, `Channels`, `Sensors`, `DAS`, `Groups`, `GroupHardware`, `CustomerDetails`
|
||||
- **DatabaseUnitTesting.Utilities** - `DatabaseAdapter`, `DatabaseComparer`
|
||||
- **DatabaseUnitTesting.Utilities.Results** - `Database`, `ResultSetParser`
|
||||
- **Properties.Settings.Default** - Application settings (`ConnectionString`, `DBName`, `DBSnapshot`)
|
||||
|
||||
### Internal Dependencies:
|
||||
- `TestSetups` is the base class for: `DefaultPropertiesTests`, `LaboratoryDetailsTests`, `DASTests`, `CustomerDetailsTests`, `DASChannelsTests`, `CalculatedChannelsTests`
|
||||
- `DBAPITests` is a partial class spread across multiple files
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Typo in Stored Procedure Names**: Comments reference `sp_LabratoryDetailsUpdateInsert` and `LabratoryDetails` table (misspelled "Laboratory" as "Labratory"). This may reflect actual database object names or be a documentation error.
|
||||
|
||||
2. **Inconsistent Stored Procedure Names in Comments**: `DASTests.cs` references `sp_CalculatedChannelsUpdateInsert` in an INSERT DAS test comment, and `sp_DASInUpdateInsert` in UPDATE comments. This appears to be copy-paste error in comments.
|
||||
|
||||
3. **Hardcoded Credentials**: `Login()` method uses hardcoded credentials "Admin" / "DTSAdmin".
|
||||
|
||||
4. **Hardcoded Database Instance**: `LOCAL_SERVER` is hardcoded as `@"(localdb)\DataPROInstance"`.
|
||||
|
||||
5. **Commented-Out Tests**: Multiple test files contain only commented-out test stubs. These document intended tests but are not executable.
|
||||
|
||||
6. **CreateFakeTestSetupWithROIs Implementation Missing**: Referenced in `RegionsOfInterest()` test but implementation not present in provided source files.
|
||||
|
||||
7. **Channel Tests Have Commented-Out Insert/Delete Calls**: In `DbAPITestsChannels.cs`, the actual `ChannelsInsert()`, `ChannelsUpdate()`, `ChannelsDelete()` calls are commented out, making tests incomplete.
|
||||
|
||||
8. **Path Construction Relies on Directory Structure**: `Setup()` method makes assumptions about build output directory structure (`bin\{architecture}\{debugOrRelease}`).
|
||||
|
||||
9. **Test Result Path Uses Relative Navigation**: `_testResultsInitialPath` uses `..\..\TestResults\` relative to `AppDomain.CurrentDomain.BaseDirectory`.
|
||||
|
||||
10. **Bridge Resistance Constant**: `FAKE_BRIDGE_RESISTANCE_OMS` is set to 350 (presumably ohms, though "OMS" may be a typo).
|
||||
59
docs/ai/DataPRO/UnitTest/DatabaseUnitTesting/Properties.md
Normal file
59
docs/ai/DataPRO/UnitTest/DatabaseUnitTesting/Properties.md
Normal file
@@ -0,0 +1,59 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Properties/Settings.Designer.cs
|
||||
generated_at: "2026-04-17T16:45:48.166150+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "414dafff4d3f4086"
|
||||
---
|
||||
|
||||
# Documentation: DatabaseUnitTesting.Properties.Settings
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module is an auto-generated settings class that provides strongly-typed access to application configuration values for the `DatabaseUnitTesting` project. It exists to centralize configuration management for database unit testing, specifically storing connection parameters, database names, and snapshot identifiers. The class is generated by Visual Studio's `SettingsSingleFileGenerator` tool and serves as the configuration layer between the unit test code and the underlying `.settings` file.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### `Settings` (sealed partial class)
|
||||
**Inherits from:** `global::System.Configuration.ApplicationSettingsBase`
|
||||
|
||||
| Member | Signature | Scope | Description |
|
||||
|--------|-----------|-------|-------------|
|
||||
| `Default` | `public static Settings Default { get; }` | Static | Returns the singleton default instance of the `Settings` class, synchronized for thread-safe access. |
|
||||
| `ConnectionString` | `public string ConnectionString { get; }` | Application-scoped | Returns the database connection string for the unit test database. Read-only. Default value points to `FAJITA\DEV_SQL` server with `DataPRO_UnitTest` catalog. |
|
||||
| `DBName` | `public string DBName { get; set; }` | User-scoped | Gets or sets the database name. Default value is `"DataPRO_UnitTest"`. |
|
||||
| `DBSnapshot` | `public string DBSnapshot { get; set; }` | User-scoped | Gets or sets the database snapshot name. Default value is `"DataPRO_UnitTestSnapshot"`. |
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
- **Auto-generated constraint**: This file is machine-generated by `Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator` version `17.10.0.0`. Manual modifications will be lost upon regeneration.
|
||||
- **Singleton pattern**: The `defaultInstance` field is created once via `Synchronized()` and returned through the `Default` property.
|
||||
- **Scope immutability**: `ConnectionString` is application-scoped (read-only at runtime); `DBName` and `DBSnapshot` are user-scoped (read/write).
|
||||
- **Type safety**: All settings are typed as `string`; accessors perform explicit casts from the underlying settings dictionary.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### This module depends on:
|
||||
- `System.Configuration.ApplicationSettingsBase` - Base class providing settings management infrastructure
|
||||
- `System.Configuration.ApplicationScopedSettingAttribute` - Attribute for application-level settings
|
||||
- `System.Configuration.UserScopedSettingAttribute` - Attribute for user-level settings
|
||||
- `System.Configuration.SpecialSettingAttribute` - Marks `ConnectionString` as a special connection string type
|
||||
- `System.Configuration.DefaultSettingValueAttribute` - Provides default values for each setting
|
||||
- `System.Runtime.CompilerServices.CompilerGeneratedAttribute` - Indicates tool-generated code
|
||||
- `System.CodeDom.Compiler.GeneratedCodeAttribute` - Metadata about the code generator
|
||||
|
||||
### What depends on this module:
|
||||
- **Inferred**: Any code within the `DatabaseUnitTesting` project that accesses configuration values via `Settings.Default`.
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Hardcoded credentials in source control**: The `ConnectionString` default value contains a plaintext SQL Server `sa` password (`!!QQAAZZxxssww22`). This is a significant security risk and should be moved to a secure configuration mechanism (e.g
|
||||
86
docs/ai/DataPRO/UnitTest/DatabaseUnitTesting/Utilities.md
Normal file
86
docs/ai/DataPRO/UnitTest/DatabaseUnitTesting/Utilities.md
Normal file
@@ -0,0 +1,86 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/ObjectsToCompare.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/DatabaseAdapter.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/DatabaseComparer.cs
|
||||
generated_at: "2026-04-17T15:54:33.868933+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "f31068a46fa2e835"
|
||||
---
|
||||
|
||||
# Database Unit Testing Utilities Documentation
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides internal utilities for comparing database objects between two databases, primarily designed to support database unit testing scenarios. It enables snapshot creation/management, object-level data comparison, and difference reporting. The three classes work together: `ObjectsToCompare` serves as a configuration container for comparison pairs, `DatabaseAdapter` provides low-level database operations (including snapshot management), and `DatabaseComparer` orchestrates the actual data comparison logic using set-based SQL operations.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### ObjectsToCompare (internal class)
|
||||
|
||||
A configuration container that holds metadata about two database objects to be compared.
|
||||
|
||||
**Constructor:**
|
||||
```csharp
|
||||
public ObjectsToCompare(string schema1Name, string object1Name, string schema2Name, string object2Name)
|
||||
```
|
||||
Initializes a new comparison pair with schema and object names for both sides.
|
||||
|
||||
**Properties:**
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `Schema1Name` | `string` | Schema name of the first object |
|
||||
| `Object1Name` | `string` | Name of the first object |
|
||||
| `Schema2Name` | `string` | Schema name of the second object |
|
||||
| `Object2Name` | `string` | Name of the second object |
|
||||
| `Qualified1` | `string` | Returns `_schema1Name + "." + _object1Name` |
|
||||
| `Qualified2` | `string` | Returns `_schema2Name + "." + _object2Name` |
|
||||
| `ColumnsToIgnore` | `IEnumerable<string>` | Returns the list of columns to exclude from comparison |
|
||||
|
||||
**Methods:**
|
||||
```csharp
|
||||
public void AddColumnToIgnore(string columnName)
|
||||
```
|
||||
Adds a column name to the internal `_columnsToIgnore` list.
|
||||
|
||||
---
|
||||
|
||||
### DatabaseAdapter (internal class)
|
||||
|
||||
Provides low-level database operations including snapshot management.
|
||||
|
||||
**Constructor:**
|
||||
```csharp
|
||||
internal DatabaseAdapter(SqlConnection connection)
|
||||
```
|
||||
Stores the connection and opens it if currently closed.
|
||||
|
||||
**Methods:**
|
||||
```csharp
|
||||
internal bool IsSnapshot(string name)
|
||||
```
|
||||
Queries `sys.databases` to check if the named database is a snapshot (checks if `source_database_id` is not null/DBNull).
|
||||
|
||||
```csharp
|
||||
internal void UseDatabase(string databaseName)
|
||||
```
|
||||
Executes `USE [databaseName]` to switch the connection context.
|
||||
|
||||
```csharp
|
||||
internal void CreateSnapshot(string databaseName, string snapshotName)
|
||||
```
|
||||
Creates a database snapshot with the file stored at `C:\Temp\[snapshotName]`.
|
||||
|
||||
```csharp
|
||||
internal void DropSnapshot(string snapshotName)
|
||||
```
|
||||
Drops the specified snapshot. Throws `ArgumentException` if the named database is not a snapshot.
|
||||
|
||||
---
|
||||
|
||||
### DatabaseComparer (internal class)
|
||||
|
||||
Orchestrates comparison
|
||||
@@ -0,0 +1,71 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/Results/Row.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/Results/Column.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/Results/Database.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/Results/Table.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/Results/ResultSetParser.cs
|
||||
- DataPRO/UnitTest/DatabaseUnitTesting/Utilities/Results/XmlFileAdapter.cs
|
||||
generated_at: "2026-04-17T15:50:55.325776+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "f6d60a0ae7a270c5"
|
||||
---
|
||||
|
||||
# Database Unit Testing Results Module Documentation
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides an in-memory representation of database result sets for unit testing purposes. It enables parsing SQL query results into a structured object model (`Database`, `Table`, `Row`, `Column`), serializing and deserializing this model to/from XML files, and comparing database states for equality. The module serves as the core data model and I/O layer for database unit testing comparisons, allowing test results to be persisted and compared against expected outcomes.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
All types in this module are `internal` to the `DatabaseUnitTesting.Utilities.Results` namespace.
|
||||
|
||||
### `Row` (class)
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| Constructor | `Row(string type)` | Creates a new row with the specified type (converted to lowercase). |
|
||||
| `AddColumn` | `void AddColumn(Column column)` | Adds a column to the row. Invalidates the cached `KeyString`. |
|
||||
| `KeyString` | `string KeyString { get; }` | Lazily computed and cached string key for comparison. Format: `_type` + `DELIMITER` + each column's `SortString`. |
|
||||
| `ColumnCount` | `int ColumnCount { get; }` | Returns the number of columns in the row. |
|
||||
| `DELIMITER` | `const string DELIMITER = "\x1e;;"` | Delimiter used when constructing `KeyString`. |
|
||||
|
||||
### `Column` (class)
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| Constructor | `Column(string name, object value)` | Creates a column with the given name and value. Value is converted via `Convert()`. `SortString` is constructed as `name.ToLower()` + `DELIMITER` + `_value`. |
|
||||
| `Convert` | `static string Convert(object value)` | Converts `object` to string. Special handling for `byte[]` (hex format "0x...") and `DateTime` (custom format with trimmed trailing zeros/colons). Other types use `ToString()`. |
|
||||
| `Name` | `string Name { get; }` | Returns the column name. |
|
||||
| `Value` | `string Value { get; }` | Returns the converted string value. |
|
||||
| `SortString` | `string SortString { get; }` | Returns the pre-computed sort/comparison string. |
|
||||
| `DELIMITER` | `const string DELIMITER = "\x1f;;"` | Delimiter used in `SortString`. |
|
||||
|
||||
### `Database` (class)
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `AddTable` | `void AddTable(Table table)` | Adds a table to the database. If the table already exists (by equality), increments its count. Updates `_tableCount` and `_hashCode`. |
|
||||
| `ContainsTable` | `bool ContainsTable(Table table)` | Returns `true` if the database contains a table equal to the given one. |
|
||||
| `GetCount` | `int GetCount(Table table)` | Returns the count of how many times the given table was added. |
|
||||
| `TableCount` | `int TableCount { get; }` | Total number of tables added (including duplicates). |
|
||||
| `Tables` | `IEnumerable<KeyValuePair<Table, int>> Tables { get; }` | Returns the internal dictionary of unique tables with their counts. |
|
||||
| `GetHashCode` | `override int GetHashCode()` | Returns the cumulative hash code of all added tables. |
|
||||
| `Equals` | `override bool Equals(object otherObject)` | Compares databases by `TableCount`, `GetHashCode()`, and verifies each table exists with the same count in the other database. |
|
||||
|
||||
### `Table` (class)
|
||||
|
||||
| Member | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| Constructor | `Table(string name1)` | Creates a table with `name1` and empty `name2`. |
|
||||
| Constructor | `Table(string name1, string name2)` | Creates a table with both names (converted to lowercase). |
|
||||
| `AddRow` | `void AddRow(Row row)` | Adds a row to the table. If a row with the same `KeyString` exists, increments its count. Updates `_rowCount` and `_hashCode`. |
|
||||
| `AddField` | `void AddField(string name, string type)` | Adds a column to the schema row. Increments `_fieldCount`. Note: hash code update is commented out. |
|
||||
| `LookupRow` | `bool LookupRow(string key, out int other)` | Looks up a row by its key string, returning the count via `out` parameter. |
|
||||
| `Schema` | `Row Schema { get; set; }` | Gets or sets the schema row. Setting updates `_fieldCount`. |
|
||||
| `Name1` | `string Name1 { get; }` | Returns the first name. |
|
||||
| `Name2` | `string
|
||||
Reference in New Issue
Block a user