bchavez / bchavez/Bogus

FinishWith for the whole generate set

Open
#55 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
9.7k
Forks
538
PR merge metrics
No merged PRs in 30d

Description

I am happy to post this somewhere else if you have a uservoice or something. It would be nice if there was a way to do finishwith on a whole set. For instance, I want to generate a collection of objects and always have the first one set to primary.

Currently I have to do the following:
```
public static Faker GetBusinessEntityRules()
{
var rules = new Faker()
.RuleFor(o => o.Code, f => f.Random.AlphaNumeric(5))
.RuleFor(o => o.Dba, f => BogusDataSets.Company.CompanyName())

return rules;
}

// Get x
var z = BogusRules.GetBusinessEntityRules().Generate(5).ToList();

// Set the first to primary
z[0].Primary = true;
```

Instead it would nice to make the rule responsible for this:
```
public static Faker GetBusinessEntityRules()
{
var rules = new Faker()
.RuleFor(o => o.Code, f => f.Random.AlphaNumeric(5))
.RuleFor(o => o.Dba, f => BogusDataSets.Company.CompanyName())
.FinishCollectionWith(list) {
.... list[0].Primary = true... etc.
}

return rules;
}
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the Faker generation flow and the RuleFor and Generate entry points shown in the issue. Define the collection-level behavior around Generate(5), including when the callback runs and how an empty collection is handled; done means a rule can set the first generated object's Primary property without post-processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.