I'm trying to create some dummy objects which have a hierachy like this:
Post
|
----User
Pret开发者_StackOverflow中文版ty simple.
Here's the code:
var user = Builder<User>.CreateNew().Build();
var posts = Builder<Post>.CreateListOfSize(100)
.All()
.With(x => x.User == user)
.Build();
But for each item, post.User
is null.
Any ideas?
should it be?
.With(x => x.User = user)
I wanted to do similar but couldn't find a way of generating user objects with different values (accepted answer would have same data for all user child objects). I ended up using AutoFixture to do this instead:
var fixture = new Fixture {RepeatCount = 100};
var posts = fixture.Repeat(fixture.Create<Post>);
精彩评论