1

I'm trying to create some dummy objects which have a hierachy like this:

Post
 |
 ----User

Pretty 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?

mezoid
  • 28,090
  • 37
  • 107
  • 148
RPM1984
  • 72,246
  • 58
  • 225
  • 350

2 Answers2

10

should it be?

.With(x => x.User = user)
mezoid
  • 28,090
  • 37
  • 107
  • 148
Petr Abdulin
  • 33,883
  • 9
  • 62
  • 96
  • HAHAH - too easy :) me =>> http://4.bp.blogspot.com/_BjW1avGcuos/StdCXBOuWaI/AAAAAAAAA2o/5tG1Dd1bTvk/s400/hillary-cackling.jpg – Pure.Krome May 09 '11 at 05:53
0

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>);
JamesM
  • 53
  • 3