Sphere10.Framework.NUnit.DB 3.2.0-ci.163.43664782937.1

This is a prerelease version of Sphere10.Framework.NUnit.DB.
dotnet add package Sphere10.Framework.NUnit.DB --version 3.2.0-ci.163.43664782937.1
                    
NuGet\Install-Package Sphere10.Framework.NUnit.DB -Version 3.2.0-ci.163.43664782937.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sphere10.Framework.NUnit.DB" Version="3.2.0-ci.163.43664782937.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sphere10.Framework.NUnit.DB" Version="3.2.0-ci.163.43664782937.1" />
                    
Directory.Packages.props
<PackageReference Include="Sphere10.Framework.NUnit.DB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sphere10.Framework.NUnit.DB --version 3.2.0-ci.163.43664782937.1
                    
#r "nuget: Sphere10.Framework.NUnit.DB, 3.2.0-ci.163.43664782937.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sphere10.Framework.NUnit.DB@3.2.0-ci.163.43664782937.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sphere10.Framework.NUnit.DB&version=3.2.0-ci.163.43664782937.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Sphere10.Framework.NUnit.DB&version=3.2.0-ci.163.43664782937.1&prerelease
                    
Install as a Cake Tool

Sphere10.Framework.NUnit.DB

Sphere10.Framework.NUnit.DB provides DACTestFixture, an NUnit base fixture for testing data-access code built on Sphere10.Framework.Data. A test opens a database scope that creates a fresh SQLite or SQL Server database and drops it when the scope ends, and the fixture adds assertions that compare table contents.

NuGet usage

Install Sphere10.Framework.NUnit.DB in a .NET 10 test project. The package depends on Sphere10.Framework.NUnit, Sphere10.Framework.Data, Sphere10.Framework.Data.Sqlite, Sphere10.Framework.Data.MSSQL and NUnit, which restore automatically. Test discovery still requires the NUnit test adapter and Microsoft.NET.Test.Sdk in the consuming test project.

Inside this repository, tests/Sphere10.Framework.Data.Tests references src/Sphere10.Framework.NUnit.DB/Sphere10.Framework.NUnit.DB.csproj instead.

Example

using NUnit.Framework;
using Sphere10.Framework.Data;
using Sphere10.Framework.NUnit;

[TestFixture]
public class CustomerTests : DACTestFixture {
	private static TableSpecification CustomerTable => new() {
		Name = "Customer",
		Type = TableType.Persistent,
		Columns = new[] {
			new ColumnSpecification { Name = "ID", Type = typeof(int), DataType = "INTEGER", Nullable = false },
			new ColumnSpecification { Name = "Name", Type = typeof(string), DataType = "VARCHAR(100)", Nullable = true }
		},
		PrimaryKey = new PrimaryKeySpecification { Columns = new[] { "ID" } }
	};

	[Test]
	[TestCaseSource(nameof(DBMS))]
	public void InsertsACustomer(DBMSType dbmsType) {
		using (var dac = EnterCreateDatabaseScope(dbmsType, CustomerTable)) {
			dac.Insert("Customer", new[] { new ColumnValue("ID", 1), new ColumnValue("Name", "Ada") });
			Assert.That(dac.Count("Customer"), Is.EqualTo(1));
		}
	}
}

DBMS lists DBMSType.Sqlite only, so this test runs against a temporary SQLite file. The scope returns a UnitTestDAC, which is an IDAC decorator that drops the database when it is disposed. DACTestFixture and UnitTestDAC are in the Sphere10.Framework.NUnit namespace.

Domains

Every folder of Sphere10.Framework.NUnit.DB is a domain with its own README, which lists all of its public types.

Domain What it provides Source

Project root

Types declared in the project folder itself:

Type Kind Purpose
DACTestFixture abstract class NUnit fixture base that creates and drops temporary SQLite or SQL Server databases, duplicates DACs and asserts table row counts and contents. Its DBMS case source lists only DBMSType.Sqlite.
UnitTestDAC class DACDecorator that runs its end action, which drops the temporary database, when it is disposed.

Testing against SQL Server

EnterCreateDatabaseScope also accepts DBMSType.SQLServer. It then creates a database with a random name on the server that the fixture was constructed with, and it drops that database at the end of the scope. The parameterless constructor uses localhost, the sa login and an empty password. To use another server, call the DACTestFixture(mssqlServer, mssqlUser, mssqlPassword) constructor from your fixture and supply a test-case source that includes DBMSType.SQLServer. Other DBMSType values throw NotImplementedException.

What's Included

DACTestFixture member Purpose
DBMS The static test-case source, which lists DBMSType.Sqlite
EnterCreateDatabaseScope(dbmsType, tables) Creates an empty database and the given TableSpecification tables, and returns a UnitTestDAC that drops the database when disposed
EnterCreateEmptyDatabaseScope(dbmsType) Does the same without creating tables
CreateEmptyDatabase, DropDatabase The virtual create and drop steps behind the scopes
DuplicateDAC(dac) Opens a second IDAC on the same database, for concurrency tests
AssertSameTableRowCount Compares the row counts of a table in two databases
AssertSameTableDataIncludingPK, AssertSameTableDataExcludingPK Compare a table's data in two databases, with or without the primary-key values, and print the rows that differ. Both need a table with a primary key, and the primary-key columns can be anywhere in the table.
AssertSingleRow, AssertManyRows, AssertManyRowsInOrder Compare a table's rows with expected values, in any order for AssertManyRows and in order for the other two
PrintTableData Writes a table's rows to the console

Dependencies

  • Sphere10.Framework.NUnit: Core NUnit utilities
  • Sphere10.Framework.Data: Data access framework
  • Sphere10.Framework.Data.Sqlite and Sphere10.Framework.Data.MSSQL: The providers that the fixture creates databases with
  • NUnit: NUnit testing framework

License & Author

License: Refer to repository LICENSE
Author: Herman Schoenfeld (sphere10.com)
Copyright: © 2018-Present Herman Schoenfeld. All rights reserved.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0-ci.163.43664782937.1 43 11/15/2026
3.2.0-ci.160.43660265392.1 44 11/15/2026
3.2.0-ci.159.43537748063.1 52 11/14/2026
3.2.0-ci.158.43536665157.1 48 11/14/2026
3.2.0-ci.157.43350632870.1 55 11/13/2026
3.2.0-ci.156.43233095581.1 52 11/12/2026