Bambit.TestUtility.DatabaseTools
1.5.2
Prefix Reserved
dotnet add package Bambit.TestUtility.DatabaseTools --version 1.5.2
NuGet\Install-Package Bambit.TestUtility.DatabaseTools -Version 1.5.2
<PackageReference Include="Bambit.TestUtility.DatabaseTools" Version="1.5.2" />
<PackageVersion Include="Bambit.TestUtility.DatabaseTools" Version="1.5.2" />
<PackageReference Include="Bambit.TestUtility.DatabaseTools" />
paket add Bambit.TestUtility.DatabaseTools --version 1.5.2
#r "nuget: Bambit.TestUtility.DatabaseTools, 1.5.2"
#:package Bambit.TestUtility.DatabaseTools@1.5.2
#addin nuget:?package=Bambit.TestUtility.DatabaseTools&version=1.5.2
#tool nuget:?package=Bambit.TestUtility.DatabaseTools&version=1.5.2
Bambit.TestUtility.DatabaseTools
Provides a set of tools for interfacing with a database for test purposes. Includes class generation from tables and verifying data.
Getting started
Install:
PM> Install-Package Bambit.TestUtility.DatabaseTools
Usage
For the following examples, we are going to use a SqlServer connection, with a database named TestDb We'll use a single table defined as:
create table dbo.[SampleTest](
[ID] int not null,
[Name] varchar(255) not null,
[DateOfBirth] Date not null
)
We also will assume the following appSettings.json config:
{
"databaseFactory": {
"databaseCatalogRecordMap": {
"sqlServer": "Bambit.TestUtility.DatabaseTools.SqlServer.SqlServerDatabaseCatalogRecord, Bambit.TestUtility.DatabaseTools.SqlServer"
},
"mappedDatabases": {
"Test1": {
"connectionString": "Server=localhost\\MMXXII; Database=IntegrationTests;Trusted_Connection=true",
"databaseCatalog": "SqlServer"
}
},
},
},
In the above json, the databaseCatalogRecordMap section defines a Dictionary of Type definitions for any type of database needed.
There are in separate libraries (such as Bambit.TestUtility.DatabaseTools.SqlServer which implements methods to access a SqlServer database).
The mappedDatabases section contains a dictionary of MappedDatabase values. The key of this dictionary will be used as the ConnectionName in calls to ITestDatabaseFactory methods. The connecitonString is the string that will be used to instantiate the connection, while the databaseCatalog is the lookup value in the databaseCatalogRecordMap
ITestDatabaseFactory
The ITestDatabaseFactory provides access to configured ITestDbConnections
and IDatabaseCatalogRecords, along with shortcuts to various methods on a given ITestDbConnection.
The concrete implemenation, TestDbConnection, requires a TestDatabaseFactoryOptions injected.
// Using IBuilder and values from a config
IConfiguration configuration=new ConfigurationBuilder()
.AddJsonFile("appSettings.json")
.Build();
TestDatabaseFactoryOptions options = Configuration.GetSection("databaseFactory").Get<TestDatabaseFactoryOptions>()!;
ITestDatabaseFactory factory=new TestDatabaseFactory(options);
TableToClassBuilder
The TableToClassBuilder requires an ITestDatabaseFactory to be injected.
TableToClassBuilder classBuilder = new(factory);
From here, you can generate Types or objects:
dynamic dynamicOption = classBuilder.GenerateObjectFromTable("Test1", "dbo", "SampleTest");
// It will have 3 fields:
dynamicOption.ID = 123;
dynamicOption.Name = "Mr. Hyde"
dynamicOption.DateOfBirth =null;
// The returned element is always a DatabaseMappedClass
DatabaseMappedClass mappedClass = classBuilder.GenerateObjectFromTable("Test1", "dbo", "SampleTest");
// This exposes a few methods:
// We can assign the values from a dictionary
Dictionary<string, object?> values = new {
{"ID", 123},
{"Name", "Mr. Hyde"},
{"DateOfBirth", new Date(2000,1,1)},
};
// We can get a property
Assert.AreEqual(mappedClass.Get<int>("ID"), 123);
IDatabaseCatalogRecord
IDatabaseCatalogRecord imeplementations provide methods to generate ITestDbConnection connections, along with some fields that are used in generating DatabaseMappedClass instances.
Implementation of this class are left for other packages as they are database specific.
ITestDbConnection
The ITestDbConnection imeplementations are wrappers around specific IDbConnection objects.
They expose some helper methods such as:
CompareTableToDataset: Compares a collecton of object arrays to values in a database tablePersist: Saves aDatabaseMappedClassto the databaseTrackInfoMessages: Enables tracking (where possible) or messages from the connection (such asprintstatements)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Bambit.TestUtility.DataGeneration (>= 1.5.2)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Bambit.TestUtility.DatabaseTools:
| Package | Downloads |
|---|---|
|
Bambit.TestUtility.DatabaseTools.SqlServer
Provides quick random data generation routines to generate or populate random objects. |
|
|
Bambit.TestUtility.DatabaseTools.SpecFlow
Step library for testing against databases. |
|
|
Bambit.TestUtility.DatabaseTools.Postgres
Provides implementation of the Bambit.TestUtility.DatabaseTools for a PostgreSql database. |
|
|
Bambit.TestUtility.DatabaseTools.Reqnroll
Step library for testing against databases. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.2 | 394 | 2/19/2025 |
| 1.5.1 | 225 | 2/18/2025 |
| 1.5.0 | 249 | 2/18/2025 |
| 1.4.4 | 352 | 1/8/2025 |
| 1.4.1 | 202 | 12/10/2024 |
| 1.4.0 | 201 | 12/10/2024 |
| 1.3.5 | 219 | 12/3/2024 |
| 1.3.3 | 219 | 11/26/2024 |
| 1.3.2 | 223 | 11/26/2024 |
| 1.3.1 | 209 | 11/26/2024 |
| 1.3.0 | 214 | 11/26/2024 |
| 1.2.4 | 216 | 11/18/2024 |
| 1.2.1 | 238 | 8/20/2024 |
| 1.2.0 | 222 | 8/19/2024 |
| 1.1.0 | 181 | 7/30/2024 |
| 1.0.2-alpha.0.22 | 94 | 7/30/2024 |
| 1.0.2-alpha.0.16 | 87 | 7/29/2024 |