GenFu
GenFu copied to clipboard
Force fill child property to override default constructor values
I have a class with a child object property. The default constructor sets an empty object to avoid NULL errors further in my production code. When trying to configure GenFu, the child property is never filled, It just leaves the "empty" value set by the default constructor. How can I override that behavior? Can it be overridden?
Sample code:
[Test]
public void Test()
{
A.Configure<MyClass>()
.Fill(x => x.Child, () => A.New<MyChildClass>());
var obj = A.New<MyClass>();
obj.Child.Value.Should().NotBeNull();
}
public class MyClass
{
public MyChildClass Child { get; set; }
public MyClass()
{
Child = new MyChildClass();
}
}
public class MyChildClass
{
public string Value { get; set; }
}
Hi , I've the same issue is there any solution for this ? @dpaquette
I don't have a workaround for you. This would require some changes to the configuration API. I will try to bump this up on the priority list
@dpaquette thank you ! 👍