Autofixture configure relationship between parent and child

坚强是说给别人听的谎言 提交于 2019-12-24 07:27:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!