Closed rsr-maersk closed 5 months ago
I think f => f.IndexFaker
already exits as an auto-increment mechanism for the index of the item currently being built. Also, there's f.IndexVariable
for more complex needs. For example,
void Main()
{
var f = new Faker<Shipment>()
.RuleFor(u => u.Id, f => f.IndexFaker)
.RuleFor(u => u.AltId, f => f.IndexVariable += 2)
.RuleFor(u => u.Receiver, f => f.Name.FirstName());
f.Generate(10).Dump();
}
class Shipment
{
public int Id;
public int AltId;
public string Receiver;
}
Going to close the issue, but feel free to continue the conversation if the example above doesn't suit your need or use case.
Description
NBuilder can provide the index of the array that is being produced. E.g.
.RuleFor((x, i) => EventTimestamp, f => f.Date.Future(i)))
This means we can do logic resolved value based on the count.
LINQPad Code Example
new Faker().RuleFor((x, i) => EventTimestamp, f => f.Date.Future(i))).Generate(5);
What alternatives have you considered?
I have to iterate over the creation instead of a 1 liner.
Could you help with a pull-request?
Yes