jeremia.morling
jeremia.morling

Reputation: 11

AutoFixture: Using GreedyConstructorQuery and still set public properties?

If I configure AutoFixture to choose constructor greedy, properties with public setters are not set. Is it possible to use GreedyConstructorQuery and still have public properties being set automatically?

Example of test that fails. If we remove the customization the test succeeds.

using AutoFixture;
using AutoFixture.Kernel;
using Xunit;

namespace ConsoleAppTests;

public class AutoFixtureCustomizationTests
{
    [Fact]
    public void TestCustomization()
    {
        var fixture = new Fixture();

        fixture.Customizations.Add(
            new MethodInvoker(
                new GreedyConstructorQuery()));

        var test1 = fixture.Create<Test1>();

        Assert.NotNull(test1.Prop2);
    }
}

public class Test1
{
    public Test1()
    {
    }

    public Test1(int? prop1)
    {
        Prop1 = prop1;
    }

    public int? Prop1 { get; set; }
    public int? Prop2 { get; set; }
}

I tried the following:

Upvotes: 0

Views: 27

Answers (0)

Related Questions