问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/29027945/autofixture-configure-relationship-between-parent-and-child