Bunnypro.SimpleFactory 1.2.0

A Simple Dotnet Factory Library For Generating Data.

Install-Package Bunnypro.SimpleFactory -Version 1.2.0
dotnet add package Bunnypro.SimpleFactory --version 1.2.0
<PackageReference Include="Bunnypro.SimpleFactory" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bunnypro.SimpleFactory --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SimpleFactory

Nuget
License

This library provide a simple object factory for generating data using Bogus as fake data generator.

Installation

dotnet add package Bunnypro.SimpleFactory

Usage Example

using Bunnypro.SimpleFactory;

// Register Factory
Factory.Register<Person>(faker => new Person
{
    Name = faker.Name.FullName(),
    Phone = faker.Phone.PhoneNumber(),
    Email = faker.Internet.Email()
});

// Generate Data
IEnumerable<Person> people = Factory.Create<Person>(4);
Person[] arrayPeople = people.ToArray();
List<Person> listPeople = people.ToList();

// Generate Unique Data
IEnumerable<Person> people = Factory.CreateUnique<Person>(4);

// Generate One Data
Person person = Factory.CreateOne<Person>();

// Extending Data
static const email = "john@doe.com";

IEnumerable<Person> people = Factory.CreateUnique<Person>(4, (person, faker) =>
{
    person.Email = email;

    return person;
});


// Register With Generate Nested Data
Factory.Register<Schedule>(faker => new Schedule
{
    People = Factory.CreateUnique<Person>(4).ToList(),
    Date = faker.Date
});

IEnumerable<Schedule> schedules = Factory.Create<Schedule>(10);


// Check Registered Factory Existence
bool personFactoryExists = Factory.Has<Person>();

// Unregister Factory
bool personFactoryRemoved = Factory.Remove<Person>();

// Clear Factory
Factory.Clear();

// Generate Without Register
double[] doubles = Factory.Once<double>(
    faker => Math.Round(faker.Random.Double(2, 4), 2) // generate double with two decimal places
).Create(4).ToArray();


// Or Another Way
Factory<double> DoubleFactory = new Factory<double>(
    faker => Math.Round(faker.Random.Double(2, 4), 2)
);

double[] doubles = DoubleFactory.Create(4).ToArray();

Factory<Person> PersonFactory = new Factory<Person>(faker => new Person
{
    FullName = faker.Person.FullName,
    Address = faker.Person.Address
});

// same as
Factory<Person> PersonFactory = Factory.Once<Person>(faker => new Person
{
    FullName = faker.Person.FullName,
    Address = faker.Person.Address
});

var people = PersonFactory.Create(100);

SimpleFactory

Nuget
License

This library provide a simple object factory for generating data using Bogus as fake data generator.

Installation

dotnet add package Bunnypro.SimpleFactory

Usage Example

using Bunnypro.SimpleFactory;

// Register Factory
Factory.Register<Person>(faker => new Person
{
    Name = faker.Name.FullName(),
    Phone = faker.Phone.PhoneNumber(),
    Email = faker.Internet.Email()
});

// Generate Data
IEnumerable<Person> people = Factory.Create<Person>(4);
Person[] arrayPeople = people.ToArray();
List<Person> listPeople = people.ToList();

// Generate Unique Data
IEnumerable<Person> people = Factory.CreateUnique<Person>(4);

// Generate One Data
Person person = Factory.CreateOne<Person>();

// Extending Data
static const email = "john@doe.com";

IEnumerable<Person> people = Factory.CreateUnique<Person>(4, (person, faker) =>
{
    person.Email = email;

    return person;
});


// Register With Generate Nested Data
Factory.Register<Schedule>(faker => new Schedule
{
    People = Factory.CreateUnique<Person>(4).ToList(),
    Date = faker.Date
});

IEnumerable<Schedule> schedules = Factory.Create<Schedule>(10);


// Check Registered Factory Existence
bool personFactoryExists = Factory.Has<Person>();

// Unregister Factory
bool personFactoryRemoved = Factory.Remove<Person>();

// Clear Factory
Factory.Clear();

// Generate Without Register
double[] doubles = Factory.Once<double>(
    faker => Math.Round(faker.Random.Double(2, 4), 2) // generate double with two decimal places
).Create(4).ToArray();


// Or Another Way
Factory<double> DoubleFactory = new Factory<double>(
    faker => Math.Round(faker.Random.Double(2, 4), 2)
);

double[] doubles = DoubleFactory.Create(4).ToArray();

Factory<Person> PersonFactory = new Factory<Person>(faker => new Person
{
    FullName = faker.Person.FullName,
    Address = faker.Person.Address
});

// same as
Factory<Person> PersonFactory = Factory.Once<Person>(faker => new Person
{
    FullName = faker.Person.FullName,
    Address = faker.Person.Address
});

var people = PersonFactory.Create(100);

  • .NETStandard 2.0

Version History

Version Downloads Last updated
1.2.0 212 4/17/2018
1.1.2 280 4/15/2018
1.1.1 287 4/13/2018
1.1.0 287 4/13/2018
1.0.1 169 4/13/2018
1.0.0 173 4/12/2018