Calling the underlying Faker<T>.Clone method on an AutoFaker<T> instance causes Generate to fail. Is this by design or a bug?
using AutoBogus;
using FluentAssertions;
using Xunit;
namespace AutoBogusSandbox;
public class Dog
{
public string Name { get; set; }
}
public class Tests
{
[Fact]
public void Calling_generate_after_clone_should_not_fail()
{
var faker = new AutoFaker<Dog>();
var clone = faker.Clone();
clone.Invoking(x => x.Generate())
.Should().NotThrow();
}
}
In any case, is there a feature supported by AutoBogus that allows me to define a common set of AutoFaker instances that can be overridden per-test? This is how I am trying to accomplish that currently:
using AutoBogus;
using FluentAssertions;
using Xunit;
namespace AutoBogusSandbox;
public class Dog
{
public string Name { get; set; }
}
public static class Fakers
{
public static AutoFaker<Dog> Dog = new();
}
public class Tests
{
[Fact]
public void Dog_is_named_sally()
{
var dog = Fakers.Dog.Clone()
.RuleFor(x => x.Name, () => "Sally")
.Generate();
dog.Name.Should().Be("Sally");
}
}
Calling the underlying
Faker<T>.Clone
method on anAutoFaker<T>
instance causesGenerate
to fail. Is this by design or a bug?In any case, is there a feature supported by AutoBogus that allows me to define a common set of
AutoFaker
instances that can be overridden per-test? This is how I am trying to accomplish that currently: