Object.Builder
1.0.0
See the version list below for details.
dotnet add package Object.Builder --version 1.0.0
NuGet\Install-Package Object.Builder -Version 1.0.0
<PackageReference Include="Object.Builder" Version="1.0.0" />
paket add Object.Builder --version 1.0.0
#r "nuget: Object.Builder, 1.0.0"
// Install Object.Builder as a Cake Addin #addin nuget:?package=Object.Builder&version=1.0.0 // Install Object.Builder as a Cake Tool #tool nuget:?package=Object.Builder&version=1.0.0
Builder
Introduction
The setup of test data, for unit, integration and end to end, is normally quite verbose and makes the tests bigger and distracting. Builder is here to help quickly and concisely create objects, populating fields and properties, allowing to specify only relevant properties for example, or create a complex object structure, or again create many instances using creation blueprints.
Features
Builder allows to:
- Create an instance of an object by specifying the type
- Create multiple instances of an object by specifying the type
- Create an instance of an object by specifying the type and creation customization
- Create multiple instances of an object by specifying the type and creation customization
Usage
Single entity creation
Single entity creation with properties and fields populated with random data. Object and collections will remain null.
T myEntity = Builder<T>.New().Build();
Single entity creation with children object
Single entity creation with properties and fields populated with random data, the integer parameter represents the nesting level to be reached to apply the generation also to objects and collections. The below example will create a root T instance with all properties and fields generate and also down to 2 level of childer and granchildren objects and collections.
T myEntity = Builder<T>.New().Build(2);
Single entity creation with custom generation
Single entity creation with properties and fields populated with random data. Object and collections will remain null. The action parameter is used to customise the initialization, for examle setting manually the desired value of a property or child object. This is useful to highlight which values are actually meaningful for the test and which is their value.
T myEntity = Builder<T>.New().Build(e => {
e.DateTimeProperty = DateTime.Now;
e.StringProperty = "My preferred value";
});
optionally is possible to also ask the builder to only use the setup action, passing the value false
for the optional parameter useRandomValues
.
This way all members will be left uninitialized, therefore they will have the default value.
T myEntity = Builder<T>.New().Build(e => {
e.DateTimeProperty = DateTime.Now;
e.StringProperty = "My preferred value";
}, false);
Multiple entities creation
Following the same behaviour of the single entity creation, the BuildMany
method allows to specify the number of entities to be generated.
IEnumerable<T> myEntity = Builder<T>.New().BuildMany(10);
Multiple entities creation with custom generation
Exactly like it happens with the Build
method which accepts an action to customise the object creation, this method allows to specify how each object is created.
The action this time takes as parameter the object to be created and an integer value which corresponds to the number of the current created object.
This index value can be used to customize property values to facilitate their identification within the list but also to add more complex generation logic.
IEnumerable<T> myEntity = Builder<T>.New().BuildMany(10, (e,i) =>
{
e.IntProperty = i;
e.StringProperty = $"My preferred value #{i}";
});
optionally is possible to also ask the builder to only use the setup action, passing the value false
for the optional parameter useRandomValues
.
This way all members will be left uninitialized, therefore they will have the default value.
IEnumerable<T> myEntity = Builder<T>.New().BuildMany(10, (e,i) =>
{
e.IntProperty = i;
e.StringProperty = $"My preferred value #{i}";
}, false);
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
- AnonymousData (>= 1.0.0)
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.2.0 | 11,143 | 2/7/2023 |
1.1.6 | 6,569 | 3/2/2022 |
1.1.5 | 805 | 2/3/2022 |
1.1.4 | 1,704 | 12/4/2021 |
1.1.3 | 342 | 11/1/2021 |
1.1.2 | 369 | 4/28/2021 |
1.1.0 | 1,994 | 3/18/2021 |
1.0.10 | 359 | 3/17/2021 |
1.0.9 | 359 | 3/17/2021 |
1.0.8 | 415 | 3/13/2021 |
1.0.7 | 348 | 3/12/2021 |
1.0.6 | 367 | 3/12/2021 |
1.0.4 | 1,917 | 2/12/2021 |
1.0.3 | 378 | 2/10/2021 |
1.0.2 | 353 | 2/6/2021 |
1.0.1 | 320 | 1/31/2021 |
1.0.0 | 432 | 12/18/2020 |
First release which includes multiple building options for typed objects.