GenFu icon indicating copy to clipboard operation
GenFu copied to clipboard

Force fill child property to override default constructor values

Open dstj opened this issue 6 years ago • 3 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; }
}

dstj avatar Oct 30 '18 15:10 dstj

Hi , I've the same issue is there any solution for this ? @dpaquette

mfarkan avatar Feb 25 '20 19:02 mfarkan

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 avatar Feb 25 '20 19:02 dpaquette

@dpaquette thank you ! 👍

mfarkan avatar Feb 25 '20 19:02 mfarkan