MisterJames / GenFu

GenFu is a library you can use to generate realistic test data. It is composed of several property fillers that can populate commonly named properties through reflection using an internal database of values or randomly created data. You can override any of the fillers, give GenFu hints on how to fill them.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Force fill child property to override default constructor values

dstj opened this issue · comments

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 ! 👍