Autofixture 配置父子关系

编程入门 行业动态 更新时间:2024-10-26 12:28:43
本文介绍了Autofixture 配置父子关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

似乎我找不到一种简单的方法来使用 autofixture 在父子之间建立关系.假设我有一个类 Order 和 OrderLine 并且 OrderLine 通过 OrderId<与 Order 链接/代码>.现在我有一个 Order 列表,我希望列表中的每个订单都有几个 OrderLine 并且 OrderLine 应该具有相同的 OrderId 根据 Order 类.

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.

如何配置这种关系?fixture.AddManyTo(orderlist) 添加许多带有许多 OrderLine 的订单,但它们都是随机的 Id 和 OrderIds.

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

fixture.Create 或 Customize 似乎不是正确的??

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

有没有什么简单的方法可以做到这一点?

Is there any easy way to do this?

推荐答案

我遇到了这个完全相同的问题,有一个 Nuget 包,它为你扩展了fixture.本质上,它确保 OrderLine.Order.Id == OrderLine.OrderId.

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.

更多推荐

Autofixture 配置父子关系

本文发布于:2023-10-25 00:12:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:父子   关系   Autofixture

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!