AutoFixture creates a property with an internal installer

Is there any way to let AutoFixture create properties using an internal setter?

I looked at the source of AutoFixture and found that in AutoPropertiesCommand the GetProperties method checks to see if the GetSetMethod ()! = Null property has. With an internal setter, this returns null unless you set the ignorePublic argument to true.

The easiest way would be to make a public setter, but in the project I'm working on, this will not be the right decision.

The following is a simplified snippet of code from a project.

public class Dummy
{
    public int Id { get; set; }
    public string Name { get; internal set; }
}

public class TestClass
{
    [Fact]
    public void Test()
    {
        var dummy = new Fixture().Create<Dummy>();
        Assert.NotNull(dummy.Name);
    }
}
+4
source share
1 answer

, internal, API. , API.

, , .

:

1 :

// [assembly:InternalsVisibleTo("Tests")]
// is applied to the assembly that contains the 'Dummy' type

[Fact]
public void Test()
{
    var fixture = new Fixture();
    var dummy = fixture.Create<Dummy>();
    dummy.Name = fixture.Create<string>();
    // ...
}

2 :

public class Dummy : IModifiableDummy
{
    public string Name { get; private set; }

    public void IModifiableDummy.SetName(string value)
    {
        this.Name = value;
    }
}

[Fact]
public void Test()
{
    var fixture = new Fixture();
    var dummy = fixture.Create<Dummy>();
    ((IModifiableDummy)dummy).SetName(fixture.Create<string>());
    // ...
}

1 , , , .
2, , , , API.

, , xUnit, AutoFixture , :

[Theory, AutoData]
public void Test(Dummy dummy, string name)
{
    ((IModifiableDummy)dummy).SetName(name);
    // ...
}

Name , Dummy, :

[Theory, InlineAutoData("SomeName")]
public void Test(string name, Dummy dummy)
{
    ((IModifiableDummy)dummy).SetName(name);
    // ...
}
+3

All Articles