DataDude 0.3.0-beta.2
See the version list below for details.
dotnet add package DataDude --version 0.3.0-beta.2
NuGet\Install-Package DataDude -Version 0.3.0-beta.2
<PackageReference Include="DataDude" Version="0.3.0-beta.2" />
paket add DataDude --version 0.3.0-beta.2
#r "nuget: DataDude, 0.3.0-beta.2"
// Install DataDude as a Cake Addin #addin nuget:?package=DataDude&version=0.3.0-beta.2&prerelease // Install DataDude as a Cake Tool #tool nuget:?package=DataDude&version=0.3.0-beta.2&prerelease
Data dude
Data Dude is a library to help create test data based on the database schema. Data dude is inspired by CaptainData but its internals and strategy differs a bit which is supposed to make it more extendable and configurable.
Get started with Data dude:
await new DataDude()
.Insert("Department")
.Insert("Employee", new { Name = "John Doe" }, new { Name = "Jane Doe" })
.Go(connection);
Concepts
Data dude is at its core an instruction handler, which means that it handles instructions. Built in are insertions and execution handling.
Inserts
Inserts are what Data dude does best. It can insert rows based on schema-knowledge and configurable handling. That way you should be able to just specify the data you acually care about. Other column values should be taken care of by the dude. With its default configuration it should be able to handle most cases, but when you encounter edge cases or want to re-configure the default behavior, there are some knobs to tweak:
InsertValueProviders
They provide default column values for the usual data types before an insert is made. If you want to add your own default values, you can configure them using shorthand like this:
await new DataDude()
.ConfigureCustomColumnValues(((column, value) => column.Name == "Active", true))
.Insert("Employee")
.Go(connection);
... or if you have more complex logic you can create your own value provider and add it like so:
public class ActiveUserValueProvider : IValueProvider
{
public void Process(ColumnInformation column, ColumnValue previousValue)
{
if (previousValue.Type == ColumnValueType.NotSet &&
column.DataType == "bit" &&
column.Table.Name == "User" &&
column.Name == "Active")
{
previousValue.Set(new ColumnValue(true));
}
}
}
dude.ConfigureInsert(x => x.InsertValueProviders.Add(new ActiveUserValueProvider()));
InsertInterceptors
These are executed before and after inserts (but after value providers have been executed). By default only one interceptor, IdentityInsertInterceptor
is configured (which handles setting and resetting identity inserts when needed). Another one can be configured using .EnableAutomaticForeignKeys()
which is an interceptor that attempts to set foreign keys for you based on previously inserted valued. You can also add your own interceptor like so:
public class AlwaysTrue : IInsertInterceptor
{
public Task OnInsert(InsertStatement statement, InsertContext context, IDbConnection connection, IDbTransaction? transaction = null)
{
foreach (var (column, value) in statement.Data)
{
if (column.DataType == "bit")
{
value.Set(new ColumnValue(true));
}
}
return Task.CompletedTask;
}
public Task OnInserted(InsertedRow insertedRow, InsertStatement statement, InsertContext context, IDbConnection connection, IDbTransaction? transaction = null)
=> Task.CompletedTask;
}
dude.ConfigureInsert(x => x.InsertInterceptors.Add(new AlwaysTrue()));
InsertRowHandlers
These are the handlers that do the actual insertion. Only the first insert handler that can handle the insert statement gets to execute the insert and return the inserted row. By default there are two insert handlers:
IdentityInsertRowHandler
handles insertion when there is only one primary key with identity. The inserted row retrieved usingSCOPE_IDENTITY()
GeneratingInsertRowHandler
handes inserts by generating unspecified primary keys when possible*
*) Uses specified default column values if possible, if not available will generate keys if data type is one if uniqueidentifier
, nvarchar
, varchar
, shortint
, int
, bigint
.
There is one other insert handler available, OutputInsertRowHandler
which uses OUTPUT identity.*
to get ahold of the inserted row, not enabled by default since the default two should cover most bases and since it it also needs to disable any table triggers in order to perform the insert, which might not be what you want. If you do want to use it, it can be plugged in like this:
dude.ConfigureInsert(x => x.InsertRowHandlers.Add(new OutputInsertRowHandler()));
Dependencies
- Dapper is used for internal data access
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Dapper (>= 2.0.35)
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 |
---|---|---|
0.8.0 | 669 | 6/30/2024 |
0.8.0-preview.5 | 3,542 | 3/11/2023 |
0.8.0-preview.4 | 7,574 | 2/21/2023 |
0.8.0-preview.3 | 97 | 2/21/2023 |
0.8.0-preview.2 | 103 | 2/20/2023 |
0.8.0-preview.1 | 105 | 2/20/2023 |
0.7.2 | 3,553 | 8/4/2021 |
0.7.1 | 385 | 7/7/2021 |
0.7.0 | 486 | 3/10/2021 |
0.6.0 | 743 | 2/3/2021 |
0.5.1 | 336 | 2/3/2021 |
0.5.0 | 418 | 1/24/2021 |
0.4.0 | 420 | 12/27/2020 |
0.4.0-beta.8 | 260 | 12/21/2020 |
0.4.0-beta.7 | 253 | 12/21/2020 |
0.4.0-beta.6 | 200 | 12/14/2020 |
0.4.0-beta.5 | 205 | 12/14/2020 |
0.4.0-beta.4 | 209 | 12/14/2020 |
0.4.0-beta.3 | 218 | 12/14/2020 |
0.4.0-beta.2 | 194 | 12/8/2020 |
0.4.0-beta.1 | 247 | 12/5/2020 |
0.3.0-beta.2 | 219 | 12/1/2020 |
0.3.0-beta.1 | 243 | 11/27/2020 |
0.2.0-beta.1 | 263 | 11/27/2020 |
0.1.0-alpha.1 | 225 | 11/12/2020 |