Factory.Generator 1.0.5

dotnet add package Factory.Generator --version 1.0.5
                    
NuGet\Install-Package Factory.Generator -Version 1.0.5
                    
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="Factory.Generator" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Factory.Generator" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Factory.Generator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Factory.Generator --version 1.0.5
                    
#r "nuget: Factory.Generator, 1.0.5"
                    
#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.
#:package Factory.Generator@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Factory.Generator&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Factory.Generator&version=1.0.5
                    
Install as a Cake Tool

Hi, This package for generation of fake data for test environment in .Net Core. After Installation, somewhere create folder Factories/ and put for any model (entity) one or more Factory file like this template, for example our Entity City:

using model_Refrence;
using My.Factory.Factories;

namespace YourNameSpace
{
    public class CityFactory : IFactory<City>
    {
        private static readonly string[] fakes = new string[]
        {
            "fake string 1",
            "fake string 2",
            "fake string 3",
        };

        public City Generate()
        {
            var random = new Random();
            return new City
            {
                Name = fakes[random.Next(fakes.Length)],
                CreatedAt = DateTime.UtcNow
            };
        }
    }
}

also you can use Bogus package for fake data:

using Bogus;
using model_Refrence;
using My.Factory.Factories;

namespace YourNameSpace
{
    public class CityFactory : IFactory<City>
    {
        public City Generate()
        {
            return new Faker<City>("en")
                .RuleFor(x => x.Name, f => f.Address.City())
                .RuleFor(x => x.CreatedAt, _ => DateTime.UtcNow)
                .Generate();
        }
    }
}

And You Can Call the Factory like This:

FactoryGenerator.GenerateAndSave<City, CityFactory>(count, appContext);

You can send third parameter is save in production mode or Not like:

FactoryGenerator.GenerateAndSave<City, CityFactory>(count, appContext, true);

also you can send forth parameter if you need to override some keys as Dictionary like:

var cities = FactoryGenerator.GenerateAndSave<City, CityFactory>(
    5,
    appContext,
    new Dictionary<string, object?>
    {
        { "Name", "new name" }
    }
);

all Name keys set new name and other keys from fake data.

also if you need add relations first create factory for your relation entities and update calling the factory like this:

var goals = FactoryGenerator.GenerateAndSave<Goal, GoalFactory>(
    5,
    db,
    relations: new HasOne<Goal, Plan, PlanFactory, int>(
        g => g.PlanId
    )
);

Goal is parent entity, Plan is relation entity, PlanFactory factory of relation entity and int is key type of foreign key.

You can easily add:

HasMany new HasMany<Plan, GoalFactory, int>(p => p.Id, g => g.PlanId)

BelongsTo new BelongsTo<Goal, UserFactory, Guid>(g => g.UserId)

also you can call instead relations like: Plan → Goal → Activity → Achievement

var achievement = FactoryGenerator.GenerateAndSave<Achievement, AchievementFactory>(
    1,
    _db,
    relations: new IFactoryRelation<Achievement>[]
    {
        new HasOne<Achievement, Activity, ActivityFactory, int>(
            a => a.ActivityId,
            childRelations: new IFactoryRelation<Activity>[]
            {
                new HasOne<Activity, Goal, GoalFactory, int>(
                    a => a.GoalId,
                    childRelations: new IFactoryRelation<Goal>[]
                    {
                        new HasOne<Goal, Plan, PlanFactory, int>(
                            g => g.PlanId
                        )
                    }
                )
            }
        )
    }
).First();
Product Compatible and additional computed target framework versions.
.NET 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. 
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.0.5 105 1/10/2026
1.0.4 91 1/10/2026
1.0.3 96 1/10/2026
1.0.2 267 8/8/2025
1.0.1 120 8/3/2025
1.0.0 114 8/3/2025