Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Elsa.Extensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Scheduling.Quartz.Unit
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Scheduling.Quartz.ComponentTests", "test\modules\scheduling\Elsa.Scheduling.Quartz.ComponentTests\Elsa.Scheduling.Quartz.ComponentTests.csproj", "{50798373-8A89-4159-BFD9-830D259538D6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fakedata", "fakedata", "{3A829F79-B19C-4100-929E-E78B86001D00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.FakeData", "src\modules\fakedata\Elsa.FakeData\Elsa.FakeData.csproj", "{5501314E-52CF-4D02-86C0-180C4F4470F2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fakedata", "fakedata", "{DCDBD383-FB19-4174-B51D-968613BEEB35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.FakeData.UnitTests", "test\modules\fakedata\Elsa.FakeData.UnitTests\Elsa.FakeData.UnitTests.csproj", "{2F9BD705-112C-44FB-81BD-48515C308CEF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "agents", "agents", "{0125BAC5-45B7-4E9B-8A2B-55F075BF537A}"
ProjectSection(SolutionItems) = preProject
.github\agents\release-notes.agent.md = .github\agents\release-notes.agent.md
Expand Down Expand Up @@ -1456,6 +1464,30 @@ Global
{50798373-8A89-4159-BFD9-830D259538D6}.Release|x64.Build.0 = Release|Any CPU
{50798373-8A89-4159-BFD9-830D259538D6}.Release|x86.ActiveCfg = Release|Any CPU
{50798373-8A89-4159-BFD9-830D259538D6}.Release|x86.Build.0 = Release|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Debug|x64.ActiveCfg = Debug|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Debug|x64.Build.0 = Debug|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Debug|x86.ActiveCfg = Debug|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Debug|x86.Build.0 = Debug|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Release|Any CPU.Build.0 = Release|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Release|x64.ActiveCfg = Release|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Release|x64.Build.0 = Release|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Release|x86.ActiveCfg = Release|Any CPU
{5501314E-52CF-4D02-86C0-180C4F4470F2}.Release|x86.Build.0 = Release|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Debug|x64.ActiveCfg = Debug|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Debug|x64.Build.0 = Debug|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Debug|x86.ActiveCfg = Debug|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Debug|x86.Build.0 = Debug|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Release|Any CPU.Build.0 = Release|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Release|x64.ActiveCfg = Release|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Release|x64.Build.0 = Release|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Release|x86.ActiveCfg = Release|Any CPU
{2F9BD705-112C-44FB-81BD-48515C308CEF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1587,6 +1619,10 @@ Global
{65B9F528-568B-4E0E-894E-F22E0B7C64BB} = {6E46B8AD-FA47-474F-B959-0B530771C28C}
{50798373-8A89-4159-BFD9-830D259538D6} = {6E46B8AD-FA47-474F-B959-0B530771C28C}
{0125BAC5-45B7-4E9B-8A2B-55F075BF537A} = {D0212324-351E-4CA6-95EE-27754B5367CC}
{3A829F79-B19C-4100-929E-E78B86001D00} = {30CF0330-4B09-4784-B499-46BED303810B}
{5501314E-52CF-4D02-86C0-180C4F4470F2} = {3A829F79-B19C-4100-929E-E78B86001D00}
{DCDBD383-FB19-4174-B51D-968613BEEB35} = {3DDE6F89-531C-47F8-9CD7-7A4E6984FA48}
{2F9BD705-112C-44FB-81BD-48515C308CEF} = {DCDBD383-FB19-4174-B51D-968613BEEB35}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {11A771DA-B728-445E-8A88-AE1C84C3B3A6}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Bogus;
using Elsa.Extensions;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;
using Elsa.Workflows.Models;

namespace Elsa.FakeData.Activities;

/// <summary>
/// Provides a base implementation for activities that generate collections of fake data
/// using the <see href="https://github.com/bchavez/Bogus">Bogus</see> library.
/// </summary>
public abstract class GenerateFakeDataActivity<T> : CodeActivity<T[]> where T : class
{
/// <inheritdoc />
protected GenerateFakeDataActivity(string? source = null, int? line = null) : base(source, line)
{
}

/// <summary>
/// The number of fake records to generate.
/// </summary>
[Input(
DisplayName = "Number of records",
Description = "The number of fake records to generate. Default: 10")]
public Input<int> Count { get; set; } = new(10);

/// <summary>
/// The locale to use when generating fake data (e.g. 'en', 'de', 'fr', 'nl').
/// See the <see href="https://github.com/bchavez/Bogus#locales">Bogus locale list</see> for all supported values.
/// </summary>
[Input(
DisplayName = "Locale",
Description = "The locale to use when generating fake data (e.g. 'en', 'de', 'fr', 'nl'). Default: en")]
public Input<string> Locale { get; set; } = new("en");

/// <summary>
/// A seed value for the random number generator.
/// Providing a seed will ensure that the same fake data is generated on each run, which can be useful for deterministic testing.
/// If not provided, a random seed will be used, resulting in different data on each execution.
/// </summary>
[Input(
DisplayName = "Seed",
Description = "With a seed, each run will produce the identical data (for deterministic tests).")]
public Input<int?> Seed { get; set; } = new((int?)null);

/// <inheritdoc />
protected override ValueTask ExecuteAsync(ActivityExecutionContext context)
{
var count = Count.Get(context);

if (count < 0)
throw new ArgumentOutOfRangeException(nameof(Count), count, "The number of records to generate must be zero or greater.");

var locale = Locale.GetOrDefault(context) ?? "en";
var seed = Seed.GetOrDefault(context, () => null);

var faker = CreateFaker(locale, seed);
var items = faker.Generate(count);

context.Set(Result, items.ToArray());

return ValueTask.CompletedTask;
Comment thread
Namoshek marked this conversation as resolved.
}
}

/// <summary>
/// Creates a configured <see cref="Faker{T}"/> instance for the given locale.
/// </summary>
/// <param name="locale">The locale string (e.g. "en", "de", "fr").</param>
/// <param name="seed">An optional seed value for deterministic data generation.</param>
/// <returns>A configured <see cref="Faker{T}"/> instance.</returns>
protected abstract Faker<T> CreateFaker(string locale, int? seed);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Globalization;
using System.Runtime.CompilerServices;
using Bogus;
using Elsa.FakeData.Extensions;
using Elsa.FakeData.Models;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;

namespace Elsa.FakeData.Activities;

/// <summary>
/// Generates a collection of fake <see cref="FakeOrder"/> records.
/// </summary>
[Activity(
Namespace = "Elsa",
Category = "Fake Data",
DisplayName = "Generate Orders",
Description = "Generates a collection of fake order records.",
Kind = ActivityKind.Task)]
public class GenerateFakeOrders : GenerateFakeDataActivity<FakeOrder>
{
/// <inheritdoc />
public GenerateFakeOrders([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
{
}

/// <inheritdoc />
protected override Faker<FakeOrder> CreateFaker(string locale, int? seed)
{
return new Faker<FakeOrder>(locale)
.When(seed is not null, f => f.UseSeed(seed!.Value))
.RuleFor(o => o.Id, f => f.Random.Guid())
.RuleFor(o => o.OrderNumber, f => f.Random.Number(100_000, 1_000_000_000).ToString(CultureInfo.InvariantCulture))
.RuleFor(o => o.OrderDate, f => f.Date.Past())
.RuleFor(o => o.Status, f => f.PickRandom("Pending", "Processing", "Shipped", "Delivered", "Cancelled"))
.RuleFor(o => o.CustomerName, f => f.Person.FullName)
.RuleFor(o => o.CustomerEmail, f => f.Person.Email)
.RuleFor(o => o.ShippingAddress, f => f.Address.FullAddress())
.RuleFor(o => o.SubTotal, f => f.Finance.Amount(10, 500))
.RuleFor(o => o.Tax, (_, o) => Math.Round(o.SubTotal * 0.1m, 2))
.RuleFor(o => o.Total, (_, o) => o.SubTotal + o.Tax);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Runtime.CompilerServices;
using Bogus;
using Elsa.FakeData.Extensions;
using Elsa.FakeData.Models;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;

namespace Elsa.FakeData.Activities;

/// <summary>
/// Generates a collection of fake <see cref="FakePerson"/> records.
/// </summary>
[Activity(
Namespace = "Elsa",
Category = "Fake Data",
DisplayName = "Generate Persons",
Description = "Generates a collection of fake person records.",
Kind = ActivityKind.Task)]
public class GenerateFakePersons : GenerateFakeDataActivity<FakePerson>
{
/// <inheritdoc />
public GenerateFakePersons([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
{
}

/// <inheritdoc />
protected override Faker<FakePerson> CreateFaker(string locale, int? seed)
{
return new Faker<FakePerson>(locale)
.When(seed is not null, f => f.UseSeed(seed!.Value))
.RuleFor(p => p.Id, f => f.Random.Guid())
.RuleFor(p => p.FirstName, f => f.Person.FirstName)
.RuleFor(p => p.LastName, f => f.Person.LastName)
.RuleFor(p => p.FullName, (f) => f.Person.FullName)
.RuleFor(p => p.Email, (f, p) => f.Person.Email)
.RuleFor(p => p.Phone, f => f.Phone.PhoneNumber())
.RuleFor(p => p.DateOfBirth, f => f.Date.Past(80, new DateTime(2000, 1, 1)));
.RuleFor(p => p.Gender, f => f.PickRandom("Male", "Female", "Non-binary"))
.RuleFor(p => p.Address, f => f.Address.StreetAddress())
.RuleFor(p => p.City, f => f.Address.City())
.RuleFor(p => p.State, f => f.Address.State())
.RuleFor(p => p.ZipCode, f => f.Address.ZipCode())
.RuleFor(p => p.Country, f => f.Address.Country());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Runtime.CompilerServices;
using Bogus;
using Elsa.FakeData.Extensions;
using Elsa.FakeData.Models;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;

namespace Elsa.FakeData.Activities;

/// <summary>
/// Generates a collection of fake <see cref="FakeProduct"/> records.
/// </summary>
[Activity(
Namespace = "Elsa",
Category = "Fake Data",
DisplayName = "Generate Products",
Description = "Generates a collection of fake product records.",
Kind = ActivityKind.Task)]
public class GenerateFakeProducts : GenerateFakeDataActivity<FakeProduct>
{
/// <inheritdoc />
public GenerateFakeProducts([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
{
}

/// <inheritdoc />
protected override Faker<FakeProduct> CreateFaker(string locale, int? seed)
{
return new Faker<FakeProduct>(locale)
.When(seed is not null, f => f.UseSeed(seed!.Value))
.RuleFor(p => p.Id, f => f.Random.Guid())
.RuleFor(p => p.Name, f => f.Commerce.ProductName())
.RuleFor(p => p.Description, f => f.Commerce.ProductDescription())
.RuleFor(p => p.Price, f => f.Finance.Amount(1, 1000))
.RuleFor(p => p.Category, f => f.Commerce.Categories(1)[0])
.RuleFor(p => p.Department, f => f.Commerce.Department())
.RuleFor(p => p.Rating, f => f.Random.Number(1, 5))
.RuleFor(p => p.Stock, f => f.Random.Int(0, 1000));
}
}
40 changes: 40 additions & 0 deletions src/modules/fakedata/Elsa.FakeData/Activities/GenerateFakeUsers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Runtime.CompilerServices;
using Bogus;
using Elsa.FakeData.Extensions;
using Elsa.FakeData.Models;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;

namespace Elsa.FakeData.Activities;

/// <summary>
/// Generates a collection of fake <see cref="FakeUser"/> records.
/// </summary>
[Activity(
Namespace = "Elsa",
Category = "Fake Data",
DisplayName = "Generate Users",
Description = "Generates a collection of fake user records.",
Kind = ActivityKind.Task)]
public class GenerateFakeUsers : GenerateFakeDataActivity<FakeUser>
{
/// <inheritdoc />
public GenerateFakeUsers([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
{
}

/// <inheritdoc />
protected override Faker<FakeUser> CreateFaker(string locale, int? seed)
{
return new Faker<FakeUser>(locale)
.When(seed is not null, f => f.UseSeed(seed!.Value))
.RuleFor(u => u.Id, f => f.Random.Guid())
.RuleFor(u => u.FirstName, f => f.Person.FirstName)
.RuleFor(u => u.LastName, f => f.Person.LastName)
.RuleFor(u => u.Username, f => f.Person.UserName)
.RuleFor(u => u.Email, f => f.Person.Email)
.RuleFor(u => u.Avatar, f => f.Person.Avatar)
.RuleFor(u => u.Roles, f => [f.PickRandom("Admin", "User", "Moderator", "Guest")])
.RuleFor(u => u.CreatedAt, f => f.Date.Past(5));
}
}
25 changes: 25 additions & 0 deletions src/modules/fakedata/Elsa.FakeData/Elsa.FakeData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>
Provides activities to generate fake data for testing and benchmarking purposes.
</Description>
<PackageTags>elsa module fakedata testing benchmarking bogus</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />

<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
</ItemGroup>

<ItemGroup Label="Elsa" Condition="'$(UseProjectReferences)' != 'true'">
<PackageReference Include="Elsa.Workflows.Management" />
</ItemGroup>

<ItemGroup Label="Elsa" Condition="'$(UseProjectReferences)' == 'true'">
<ProjectReference Include="..\..\..\..\..\elsa-core\src\modules\Elsa.Workflows.Management\Elsa.Workflows.Management.csproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/modules/fakedata/Elsa.FakeData/Extensions/ModuleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Elsa.Extensions;
using Elsa.FakeData.Features;
using Elsa.Features.Services;

namespace Elsa.FakeData.Extensions;

/// <summary>
/// Provides extension methods for configuring fake data services.
/// </summary>
public static class ModuleExtensions
{
/// <summary>
/// Installs the FakeData module.
/// </summary>
public static IModule UseFakeData(this IModule module, Action<FakeDataFeature>? configure = null)
{
return module.Use(configure);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Elsa.FakeData.Extensions;

internal static class ObjectExtensions
{
public static T When<T>(this T obj, bool condition, Func<T, T> action)
{
return condition ? action(obj) : obj;
}
}
22 changes: 22 additions & 0 deletions src/modules/fakedata/Elsa.FakeData/Features/FakeDataFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Elsa.Extensions;
using Elsa.Features.Abstractions;
using Elsa.Features.Services;

namespace Elsa.FakeData.Features;

/// <summary>
/// A feature that provides activities to generate fake data for testing and benchmarking purposes.
/// </summary>
public class FakeDataFeature : FeatureBase
{
/// <inheritdoc/>
public FakeDataFeature(IModule module) : base(module)
{
}

/// <inheritdoc />
public override void Configure()
{
Module.AddActivitiesFrom<FakeDataFeature>();
}
}
1 change: 1 addition & 0 deletions src/modules/fakedata/Elsa.FakeData/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd" />
Loading