GalaxyCheck icon indicating copy to clipboard operation
GalaxyCheck copied to clipboard

Allow overriding members on registered gens

Open nth-commit opened this issue 3 years ago • 0 comments

Test case:

private record RecordWithOneProperty2(int Property);

[Fact]
public void ItCanOverrideAMemberOfATypeRegisteredInTheFactory()
{
    var genFactory = Gen
        .Factory()
        .RegisterType(Gen.Constant(new RecordWithOneProperty2(1)));

    var gen = genFactory
        .Create<RecordWithOneProperty2>()
        .OverrideMember(x => x.Property, Gen.Constant(2));

    var instance = gen.SampleOne();

    instance.Property.Should().Be(2);
}

It's super intuitive that this behavior should exist, it even got me.

But;

It's non-trivial to implement right now because the generation is currently handled, completely opaquely, by the generator passed to RegisterType. It's almost like we'll have to analyze the generated type after-the-fact, and actually override pre-generated values - which is not like anything done before in this library.

nth-commit avatar Aug 04 '22 08:08 nth-commit