When i set property with "with" method, its leave null all propertys on nested objects which same named.
(im using autofixture's latest version as 3.0.8)
public class Something {
public string Id { get; set; }
public IList<Something> Things { get; set; }
}
var obj = Fixture.Build<Something>().With(q => q.Id, "something").CreateAnonymous()
In this situation, obj.Id == "something" equals to true, but also obj.Things[0].Id == null equalsto true.
I think there is a bug or im mistaken; Anyone may help?
By default, AutoFixture will not create an instance of Something
because the graph contains a circular reference.
What you can do is to add / remove the appropriate behaviors on the Fixture
instance:
fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
You can now create an instance of Something
however the Things
property (circular reference) is now omitted.
That's why you get an empty list..
However, you can customize the creation algorithm even further:
var obj = fixture.Build<Something>()
.With(x => x.Id,
"something")
.With(x => x.Things,
fixture.CreateMany<Something>().ToList())
.Create();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With