--- 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` | 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