Skip to content
akovanev edited this page Nov 18, 2022 · 24 revisions

Setup

Install Akov.DataGenerator NuGet package.

dotnet add package Akov.DataGenerator

Changelog

Version Change
1.0 - 1.2 Not supported. Generation based on json files only.
1.3 Akov.DataGenerator.Attributes added.
1.3.1 Min array size, range validation for DgLength, DgSpacesCount, DgFailure added for attributes.
1.4.0 Fluent mapper profiles added.
1.4.1 DG extended with GenerateObject methods and FileReadConfig.
1.5.0 Assigning the properties values added to mapper profiles.

Usage

Akov.DataGenerator library helps to generate random data based on its internal DataScheme.

There are three main ways how the DataScheme can be obtained.

The DG output for the first two can then be represented as a json string or a generic object.

string GenerateJson(DataScheme scheme)
T GenerateObject<T>(DataScheme scheme)

When dealing with profiles there is no public method populating the DataScheme. Instead you can directly get the output.

string GenerateJson<T>(DgProfileBase profile)
T GenerateObject<T>(DgProfileBase profile)

What should you be aware of?

At this moment, object generation is literally deserialization of the built json.

Json first approach was chosen to introduce Random Failure feature. If it is enabled, then the generated json is supposed to be invalid/incorrect for some objects, and deserialization may fail unless specific error handling is added. Like in this example based on Newtonsoft.Json usage. Unfortunately, System.Text.Json doesn't support this behavior yet.

Clone this wiki locally