Files
2026-04-17 14:55:32 -04:00

3.0 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/UnitTest/DatabaseUnitTesting/Utilities/ObjectsToCompare.cs
DataPRO/UnitTest/DatabaseUnitTesting/Utilities/DatabaseAdapter.cs
DataPRO/UnitTest/DatabaseUnitTesting/Utilities/DatabaseComparer.cs
2026-04-17T15:54:33.868933+00:00 zai-org/GLM-5-FP8 1 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:

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:

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:

internal DatabaseAdapter(SqlConnection connection)

Stores the connection and opens it if currently closed.

Methods:

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).

internal void UseDatabase(string databaseName)

Executes USE [databaseName] to switch the connection context.

internal void CreateSnapshot(string databaseName, string snapshotName)

Creates a database snapshot with the file stored at C:\Temp\[snapshotName].

internal void DropSnapshot(string snapshotName)

Drops the specified snapshot. Throws ArgumentException if the named database is not a snapshot.


DatabaseComparer (internal class)

Orchestrates comparison