Akov.DataGenerator
2.0.0-alpha.1
See the version list below for details.
dotnet add package Akov.DataGenerator --version 2.0.0-alpha.1
NuGet\Install-Package Akov.DataGenerator -Version 2.0.0-alpha.1
<PackageReference Include="Akov.DataGenerator" Version="2.0.0-alpha.1" />
<PackageVersion Include="Akov.DataGenerator" Version="2.0.0-alpha.1" />
<PackageReference Include="Akov.DataGenerator" />
paket add Akov.DataGenerator --version 2.0.0-alpha.1
#r "nuget: Akov.DataGenerator, 2.0.0-alpha.1"
#:package Akov.DataGenerator@2.0.0-alpha.1
#addin nuget:?package=Akov.DataGenerator&version=2.0.0-alpha.1&prerelease
#tool nuget:?package=Akov.DataGenerator&version=2.0.0-alpha.1&prerelease
DataGenerator
Data Generator. Give it a ⭐ if you find it useful. <hr/>
Key features:
Calculated properties
// Given: FirstName and LastName are randomly generated.
// The email is dynamically constructed based on their values using the following template:
.Property(s => s.Email).Construct(s => $"{s.FirstName}.{s.LastName}@mycompany.com")
String templates
Templates support placeholders for number ranges, resources, and file content. For example, a template like:
"Note: [number:100-999] [resource:Firstnames] [file:lastnames.txt]"
Could generate an output such as:
"Note: 137 Jessica Torres".
Decorators
Enhance the freshly generated random value using decorators.
.Property(s => s.Name)
.Template("[resource:Nouns]")
.Decorate(r => CapitalizeFirstLetter(r?.ToString()))
Random generation rules
Defines rules for generating values, each associated with a probability.
The probability of the main generation flow (P<sub>m</sub>) is calculated as: P<sub>m</sub> = 1 - ΣP<sub>i</sub>
Where P<sub>i</sub> represents the probability of each individual generation rule.
// Generates a negative value in the range of [-5, -1) with a probability of 0.1 (10%).
.Property(s => s.Year)
.Range(1,5)
.GenerationRule("NegativeYear", 0.1, _ => Random.Shared.Next(-5, -1))
Nullable rule
Defines the probability for the null value. The property type should either be nullable or have nullable reference type enabled.
// Precondition
class Student
{
public string? FirstName {get; set; }
public string LastName {get; set; }
}
// Great job :)
.Property(s => s.FirstName)
.Template("[file:firstnames.txt]")
.Nullable(0.25)
// Will throw an exception :(
.Property(s => s.FirstName)
.Template("[file:lastnames.txt]")
.Nullable(0.25)
Custom generators
// A custom generator should inherit from `GeneratorBase<T>`
public class PhoneGenerator : GeneratorBase<string>
{
private const char SpecialSymbol = '#';
public override string CreateRandomValue(Property property)
{
var mask = property.GetValueRule("PhoneMask") ?? "### ### ###";
var builder = new StringBuilder();
Random random = GetRandomInstance(property);
foreach (var c in mask.ToString()!)
builder.Append(c != SpecialSymbol ? c : random.Next(0, 10).ToString());
return builder.ToString();
}
}
// Usage
.Property(s => s.Phone)
.UseGenerator(new PhoneGenerator())
.ValueRule("PhoneMask", "## ## ## ##")
Generators
BooleanGeneratorDatetimeGeneratorDecimalGeneratorDoubleGeneratorEmailGeneratorEnumGeneratorGuidGeneratorIntGeneratorIpGeneratorPhoneGeneratorStringGenerator
Example
var scheme = new DataScheme();
//StudentGroup
scheme.ForType<StudentGroup>()
.Property(s => s.Name).Template("[resource:Nouns]").Decorate(r => Utility.CapitalizeFirstLetter(r?.ToString()))
.Property(s => s.Students).Count(3, 5);
//Student
scheme.ForType<Student>()
.Property(s => s.FirstName).Template("[resource:Firstnames]")
.Property(s => s.LastName).Template("[file:lastnames.txt]").Nullable(0.25)
.Property(s => s.Email).Construct(s => $"{Utility.BuildNameWithoutSpaces(s.FirstName, s.LastName)}" +
$"{TemplateProcessor.CreateValue(Random.Shared,"@[resource:Domains]")}")
.Property(s => s.BirthDay).Range(DateTime.Today.AddYears(-60), DateTime.Today.AddYears(-16)).Nullable(0.1)
.Property(s => s.Year).Range(1,5).GenerationRule("NegativeYear", 0.5, _ => Random.Shared.Next(-5, -1))
.Property(s => s.Courses).Count(2,4)
.Property(s => s.Note).Template("Note: [number:100-999] [resource:Firstnames] [file:lastnames.txt]");
//Contact
scheme.ForType<Contact>()
.Property(s => s.Phone).UseGenerator(new PhoneGenerator()).PhoneMask("## ## ## ##")
.Property(s => s.Address).Template("[resource:Addresses]")
.Property(s => s.IpAddress).UseGenerator(new IpGenerator()).Nullable(0.5);
var dataGenerator = new SimpleDataGenerator(scheme);
var randomStudentCollection = dataGenerator.GenerateForType<StudentGroup>();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 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 is compatible. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | 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.1
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
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 |
|---|---|---|
| 2.2.0 | 252 | 12/4/2025 |
| 2.1.4 | 718 | 3/11/2025 |
| 2.1.3 | 351 | 3/10/2025 |
| 2.1.2 | 319 | 3/10/2025 |
| 2.1.1 | 356 | 3/5/2025 |
| 2.1.0 | 354 | 3/5/2025 |
| 2.0.0 | 336 | 3/5/2025 |
| 2.0.0-alpha.1 | 234 | 3/5/2025 |
| 1.11.0 | 255 | 2/27/2025 |
| 1.10.0 | 616 | 11/14/2023 |
| 1.9.1 | 886 | 1/11/2023 |
| 1.9.0 | 850 | 1/8/2023 |
| 1.8.2 | 834 | 12/18/2022 |
| 1.8.1 | 823 | 12/14/2022 |
| 1.8.0 | 869 | 12/7/2022 |
| 1.7.1 | 846 | 12/5/2022 |
| 1.7.0 | 864 | 12/5/2022 |
| 1.6.4 | 887 | 11/30/2022 |
| 1.6.2 | 877 | 11/23/2022 |