Akov.DataGenerator 1.10.0

dotnet add package Akov.DataGenerator --version 1.10.0                
NuGet\Install-Package Akov.DataGenerator -Version 1.10.0                
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="Akov.DataGenerator" Version="1.10.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Akov.DataGenerator --version 1.10.0                
#r "nuget: Akov.DataGenerator, 1.10.0"                
#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.
// Install Akov.DataGenerator as a Cake Addin
#addin nuget:?package=Akov.DataGenerator&version=1.10.0

// Install Akov.DataGenerator as a Cake Tool
#tool nuget:?package=Akov.DataGenerator&version=1.10.0                

DataGenerator

alternate text is missing from this package README image alternate text is missing from this package README image

Generates data randomly. Give it a ⭐ if you find it useful.

Key features:

  • Calculated properties.
.Property(c => c.Count).IsCalc() // Custom calc generator will define the logic rules
  • Assigned properties.
.Property(s => s.FullName).Assign(s => $"{s.FirstName} {s.LastName}") // FirstName and LastName are random here
  • Random failures.
.Property(s => s.Signature).Length(4, 16)
    .Failure(
        nullable: 0.1, // 10% for null value
        custom: 0.1,   // 10% for bad value
        range: 0.05);  // 5% for out of range. Here that means lenght < 4 or > 16 
  • Predefined list of firstnames, lastnames, companies, addresses, cities, countries.
.Property(s => s.Company).FromResource(ResourceType.Companies)
  • Repeat last run
dg.GenerateJson<StudentCollection>(profile!, useLast: true);

Links

History

Originally this library was created in order to prepare json mocked data for testing api, which was under development. Api was supposed to aggregate data from a bunch of backend systems, while the client had to import several hundred thousand objects to a new frontend cms. It was extremely important to make sure that all data format surprises, which we were getting, could have been handled properly. That's why random failures were added to DG. As well as random sized arrays. At the same time, it was impossible to import an object if all properties contained completely random data. This is where calculated properties hepled.

After that I didn't work with DG for almost two years. During this time a couple of nice tools, helping out with fake data, appeared. Some time ago, I was working on the other issue, where data couldn't be too random again. I realized, that DG may get its second chance and got back to updating it with new features, primarily focusing on building a more convenient setup, based on the fluent syntax.

DG, at this moment, is quite far from being optimal in terms of performance as well as in code experience, test coverage or documentation. But if you see that there could be nice features added, feel free to create a github issue or discussion.

Generators

  • BooleanGenerator
  • ByteArrayGenerator
  • CompositeStringGenerator
  • DatetimeGenerator
  • DecimalGenerator
  • DoubleGenerator
  • EmailGenerator
  • GuidGenerator
  • IntGenerator
  • IpGenerator
  • PhoneGenerator
  • SetGenerator list of values and enums
  • StringGenerator

Special generators

  • AssignGenerator
  • CalcGeneratorBase

Example

// In StudentsTestProfile profile constructor
ForType<Student>()
    .Ignore(s => s.HasWarnings).Ignore(s => s.IsValid)
    .Property(s => s.Id).Failure(nullable: 0.2)
    .Property(s => s.FirstName).FromFile("firstnames.txt").Failure(nullable: 0.1)
    .Property(s => s.LastName).FromResource(ResourceType.LastNames).Failure(nullable: 0.1)
    .Property(s => s.FullName).Assign(s => $"{s.FirstName} {s.LastName}")
    .Property(s => s.Year).UseGenerator("MyUint").Range(5)
    .Property(s => s.Variant).HasJsonName("test_variant")
    .Property(s => s.TestAnswers).HasJsonName("test_answers").Length(5).Range(1, 5)
    .Property(s => s.EncodedSolution).HasJsonName("encoded_solution")
        .Pattern(StringGenerator.AbcNum).Length(15, 50).Spaces(1,3)
        .Failure(0.1, 0.1, 0.05, "####-####-####" )
    .Property(s => s.LastUpdated).HasJsonName("last_updated").Pattern("dd/MM/yy")
        .Range("20/10/19","01/01/20").Failure(0.2, 0.2, 0.1)
    .Property(s => s.Subjects).Length(4)
    .Property(s => s.Discount).Pattern("##.##").Range(9.50, 99.50)
    .Property(s => s.Signature).Length(4, 16).Failure(nullable: 0.1);

ForType<Address>()
    .Property(s => s.Company).FromResource(ResourceType.Companies).Failure(nullable: 0.1)
    .Property(s => s.Phone).UseGenerator(TemplateType.Phone)
        .Pattern("+45 ## ## ## ##;+420 ### ### ###")
        .Failure(nullable: 0.05)
    .Property(s => s.Email).UseGenerator(TemplateType.Email).Failure(nullable: 0.1)
    .Property(s => s.AddressLine).FromResource(ResourceType.Addresses).Failure(nullable: 0.25)
    .Property(s => s.City).FromResource(ResourceType.Cities).Failure(nullable: 0.1)
    .Property(s => s.Country).FromResource(ResourceType.Countries).Failure(nullable: 0.15)
    .Property(s => s.IpAddress).UseGenerator(TemplateType.IpV4).Failure(nullable: 0.1);

// Execute 
var dg = new DG(new StudentGeneratorFactory(), new DataSchemeMapperConfig { UseCamelCase = true }); 

// Json
string jsonData = dg.GenerateJson<StudentCollection>(new StudentsTestProfile());
//or objects
IEnumerable<Student> students = dg.GenerateObjectCollection<Student>(new StudentsTestProfile(), 100); 

Product 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 is compatible.  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. 
.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. 
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
1.10.0 500 11/14/2023
1.9.1 724 1/11/2023
1.9.0 696 1/8/2023
1.8.2 680 12/18/2022
1.8.1 674 12/14/2022
1.8.0 697 12/7/2022
1.7.1 683 12/5/2022
1.7.0 707 12/5/2022
1.6.4 715 11/30/2022
1.6.2 719 11/23/2022
1.6.1 753 11/23/2022
1.6.0 704 11/21/2022
1.5.2 718 11/20/2022
1.5.1 695 11/19/2022
1.5.0 725 11/18/2022
1.4.1 735 11/16/2022
1.4.0 799 7/31/2022
1.3.1 915 9/24/2020
1.3.0 855 9/7/2020
1.2.0 1,009 8/31/2020 1.2.0 is deprecated because it is no longer maintained.