Skip to content

AutoFaker[T] Clone Breaking #102

@codyspeck-ppa

Description

@codyspeck-ppa

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");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions