1

It seems like I can't find an easy way to create relationship between parent and child using autofixture. Let is say I have a class Order and OrderLine and OrderLine is linked with Order by OrderId. Now I have a list of Orders and I want that each order inside the list have a few OrderLine and OrderLine should have the same OrderId as per the Order class.

How to configure this relationship? fixture.AddManyTo(orderlist) adds many orders with many OrderLines but they are all random Ids and OrderIds.

fixture.Create or Customize doesn't seem to be the right ones??

Is there any easy way to do this?

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
user1829319
  • 691
  • 1
  • 8
  • 22
  • 2
    Here's a useful [comment](http://stackoverflow.com/questions/19840537/creating-a-domain-model-without-circular-references-in-entity-framework#comment29586458_19840537), and a related [answer](http://stackoverflow.com/a/18601592/467754) to this question. – Nikos Baxevanis Mar 13 '15 at 09:05
  • Hi, this looks like an answer though not sure how to mark it as answer – user1829319 Mar 13 '15 at 22:21
  • Sorry this is not a solution for me. I realised AutoDataAttribute is not supported in MSTest so the solution does not really work for me!! – user1829319 Mar 22 '15 at 04:19
  • That's not a problem. Just use the `Fixture` instance directly, then. – Nikos Baxevanis Mar 30 '15 at 08:31

1 Answers1

0

I had come across this exact same issue, there is a Nuget package which extends fixture for you. In essence it makes sure that OrderLine.Order.Id == OrderLine.OrderId.

Ruskin
  • 1,504
  • 13
  • 25