开发者

NBuilder - Issue Creating Nested Object

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>);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜