Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force fill child property to override default constructor values #142

Open
dstj opened this issue Oct 30, 2018 · 3 comments
Open

Force fill child property to override default constructor values #142

dstj opened this issue Oct 30, 2018 · 3 comments

Comments

@dstj
Copy link

dstj commented Oct 30, 2018

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; }
}
@mfarkan
Copy link

mfarkan commented Feb 25, 2020

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

@dpaquette
Copy link
Collaborator

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

@mfarkan
Copy link

mfarkan commented Feb 25, 2020

@dpaquette thank you ! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants