![]() |
VOOZH | about |
dotnet add package JLib.DataGeneration --version 0.12.0
NuGet\Install-Package JLib.DataGeneration -Version 0.12.0
<PackageReference Include="JLib.DataGeneration" Version="0.12.0" />
<PackageVersion Include="JLib.DataGeneration" Version="0.12.0" />Directory.Packages.props
<PackageReference Include="JLib.DataGeneration" />Project file
paket add JLib.DataGeneration --version 0.12.0
#r "nuget: JLib.DataGeneration, 0.12.0"
#:package JLib.DataGeneration@0.12.0
#addin nuget:?package=JLib.DataGeneration&version=0.12.0Install as a Cake Addin
#tool nuget:?package=JLib.DataGeneration&version=0.12.0Install as a Cake Tool
This library allows you to manage your testing data using packages and simplifies the use of Ids.
A Data Package can define public Id-Properties which will be automatically set to the same id each time the test is run. The Id can be either a int, Guid, or a derivative of IntValueType or GuidValueType. The int and Guid Ids are persisted in a file stored next to the project file, containing all ids for the entire project. there are two variants of ids: property and named ids.
A property id is defined by adding a property of one of the types noted above to the data package. The getter should be public and the setter must be present and protected. To get the property id of another package, inject the package and access the property.
A runtime id is required when Ids are created at runtime, for example when creating a new entity in the database.
To resolve the issue of being unable to resolve this id, an abstraction layer is used.
When running production code, the JLib.DataGeneration.Abstractions package can be used to create IDs using the IIdGenerator. It can be added to the service collection via IdGeneratorServiceCollectionExtensions.AddIdGenerator.
When running tests, another IIdGenerator will be added automatically when calling DataPackageExtensions.AddDataPackages.
By injecting the implementation TestingidGenerator additional method for creating int and string ids are porovided.
This IdGenerator uses the Stacktrace, specifically the identity (class + method name + generic argument count / generic parameters + parameters) of the caller of the TestingIdGenerator
Only the generic type arguments of the method are included in the identity due to technical limitations.
A named id is defined by getting it from the datapackage base class. the name must be unique per dataPackage. NamedIDs should be used when it is not neccessary to reference this entity from another entity like when creating a n:m reference entity. The name of the id should contain the propertynames of the related ids (for example when you create orderItems for the order named 'CompletedOrder', the name should be 'CompletedOrder_Item_1') A named Id can not be accessed from another package.
A manual Id is a id which can be defined at runtime. It is composed of a groupName and a IdName. You MUST NOT select the classname of any DataPackage. Doing so might result in duplicate IDs.
during debugging, you can simply use the .Info/
using JLib.DataGeneration;
// ...
public class MyDataPackage : DataPackage
{
public MyDataPackage(IDataPackageStore dataPackages) : base(dataPackages)
{
}
}
To create deterministic ids, add a public property of type guid or a derivative of GuidValueType to your DataPackage
using JLib.DataGeneration;
using JLib.ValueTypes;
// ...
#pragma warning disable CS8602 // Dereference of a possibly null reference.
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
namespace MyNamespace;
#region referenced types
// id valuetype
public record ArticleId(Guid Value) : GuidValueType(Value);
// efcore entity
public class Article
{
[Key]
Guid Id { get; init; }
string Name { get; init; }
}
public class ShopDbContext : DbContext
#endregion
// DataPackage
public class MyDataPackage : DataPackage
{
public ArticleId ArticleId { get; init; }
public MyDataPackage(DataPackageManager packageManager, MyDbContext dbContext):base(packageManager)
{
dbContext.Articles.Add(new()
{
Id = ArticleId.Value,
Name = GetInfoText(nameof(ArticleId))
});
}
}
public class UnitTest : IDisposable
{
[Fact] public async Task ImportLocationsOnly() => await RunTest(new[] { typeof(NotImportedLocationsDp) });
private readonly CancellationToken _cancellationToken;
private readonly IServiceProvider _provider;
private readonly List<IDisposable> _disposables = new();
private readonly ITypeCache _typeCache;
public UnitTest()
{
var id = Guid.NewGuid();
var exceptions = new ExceptionBuilder("test setup");
var services = new ServiceCollection()
.AddTypeCache(out _typeCache, exceptions,
BackendTestsTypePackage.Instance, JLibDataGenerationTypePackage.Instance)
.AddAutoMapper(p => p.AddProfiles(_typeCache))
.AddDataPackages(_typeCache)
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on JLib.DataGeneration:
| Package | Downloads |
|---|---|
|
JLib
Metapackage for all JLIb packages |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.12.0 | 147 | 1/15/2026 |
| 0.11.2 | 335 | 5/12/2025 |
| 0.11.1 | 210 | 2/21/2025 |
| 0.11.0 | 197 | 2/19/2025 |
| 0.10.0 | 204 | 2/17/2025 |
| 0.9.5 | 323 | 1/30/2025 |
| 0.9.4 | 206 | 1/29/2025 |
| 0.9.3 | 215 | 1/28/2025 |
| 0.9.2 | 202 | 1/22/2025 |
| 0.9.1 | 207 | 1/22/2025 |
| 0.9.0 | 223 | 1/20/2025 |
| 0.8.8 | 397 | 10/18/2024 |
| 0.8.7 | 263 | 10/18/2024 |
| 0.8.6 | 203 | 10/17/2024 |
| 0.8.5 | 251 | 9/18/2024 |
| 0.8.4 | 235 | 9/18/2024 |
| 0.8.3 | 241 | 9/11/2024 |
| 0.8.1 | 218 | 9/2/2024 |
| 0.8.0 | 243 | 8/28/2024 |
| 0.7.6 | 214 | 8/27/2024 |