小编Jay*_*Jay的帖子

使用自动混合控制对象树的生成深度

我试图用Autofixture控制对象树的生成深度.在某些情况下,我只想生成根对象,在另一组情况下,我可能想要生成一个特定深度的树(2,3,比方说).

class Foo {
    public string Name {get;set;}
    public Bar Bar {get;set;}
    public AnotherType Xpto {get;set;}
    public YetAnotherType Xpto {get;set;}
}

class Bar {
    public string Name {get;set;}
    public string Description {get;set;}
    public AnotherType Xpto {get;set;}
    public YetAnotherType Xpto {get;set;}
    public Xpto Xpto {get;set;}
}

class Xpto {
    public string Description {get;set;}
    public AnotherType Xpto {get;set;}
    public YetAnotherType Xpto {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

通过上面的例子,我希望(深度1)控制生成过程,以便只实例化Foo类,并且不填充该类的Bar属性或任何其他引用类型,或者(深度2)我想要Foo类实例化后,Bar属性使用新的Bar实例填充,但Xpto属性或该类上的任何其他引用类型未填充.

如果我没有在代码库中发现它,Autofixture是否有自定义或行为允许我们进行这种控制?

同样,我想要控制的不是递归,而是对象图的填充深度.

c# autofixture

10
推荐指数
2
解决办法
1901
查看次数

标签 统计

autofixture ×1

c# ×1