public void can_create_a_simple_clone() { var orderFaker = new Faker <Examples.Order>() .UseSeed(88) .RuleFor(o => o.OrderId, f => f.IndexVariable++) .RuleFor(o => o.Quantity, f => f.Random.Number(1, 3)) .RuleFor(o => o.Item, f => f.Commerce.Product()); var clone = orderFaker.Clone(); var clonedOrder = clone.Generate(); var rootOrder = orderFaker.Generate(); clonedOrder.ShouldBeEquivalentTo(rootOrder); }
public void parallel_determinism() { var orderFaker = new Faker <Examples.Order>() .RuleFor(o => o.OrderId, f => f.IndexVariable++) .RuleFor(o => o.Quantity, f => f.Random.Number(1, 3)) .RuleFor(o => o.Item, f => f.Commerce.Product()); var orders = ParallelEnumerable.Range(1, 5) .Select(threadId => orderFaker .Clone() .UseSeed(88) .Generate(4).ToArray() ).ToArray(); foreach (var orderOfFour in orders) { CheckSequence(orderOfFour); } }
public void clone_has_different_rules() { var rootFaker = new Faker <Examples.Order>() .UseSeed(88) .RuleFor(o => o.OrderId, f => f.IndexVariable++) .RuleFor(o => o.Quantity, f => f.Random.Number(1, 3)) .RuleFor(o => o.Item, f => f.Commerce.Product()); var cloneFaker = rootFaker.Clone() .RuleFor(o => o.Quantity, f => f.Random.Number(4, 6)); var rootOrder = rootFaker.Generate(); var clonedOrder = cloneFaker.Generate(); rootOrder.Quantity.Should() .BeGreaterOrEqualTo(1).And .BeLessOrEqualTo(3); clonedOrder.Quantity.Should() .BeGreaterOrEqualTo(4).And .BeLessOrEqualTo(6); }
public void github_issue121_workaround() { var faker = new Faker <TestObject>() .StrictMode(true) .RuleFor(x => x.Id, x => Guid.NewGuid()) .RuleFor(x => x.Name, x => x.Person.FirstName); var updateFaker = faker.Clone() .Ignore(x => x.Id); var obj = faker.Generate(); var id = obj.Id; // value copy var name = obj.Name; // value copy updateFaker.Populate(obj); console.Dump($"Copy values - id: {id}, name: {name}"); console.Dump(obj); id.Should().Be(obj.Id); name.Should().NotBe(obj.Name); }