New behavior FillWithSequentialValuesBehavior
Features
This PR brings a new Behavior, FillWithSequentialValuesBehavior
, which can initialize properties values that are sequential, according to their types.
This is especially useful when initializing collections. This behavior may be made default in version 5.
Example
The example below shows how to enable this behavior.
var people = MagicFactory
.For<ClassWithInteger>()
.WithBehavior(new FillWithSequentialValuesBehavior())
.Many(100)
.Build();
people[0].Name.Should().Be("Name1");
people[0].Age.Should().Be(1);
people[0].Address.ZipCode.Should().Be("ZipCode1");
people[1].Name.Should().Be("Name2");
people[1].Age.Should().Be(2);
people[1].Address.ZipCode.Should().Be("ZipCode2");
public class Customer
{
public string Name { get; set; }
public int Age { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string ZipCode { get; set; }
}
Options
The behavior also supports disabling recursion.
var people = MagicFactory
.For<ClassWithInteger>()
.WithBehavior(new FillWithSequentialValuesBehavior(options => options.Recursive = false))
.Many(100)
.Build();
people[0].Name.Should().Be("Name1");
people[0].Address.Should().BeNull();
people[1].Name.Should().Be("Name2");
people[1].Address.Should().BeNull();