简体   繁体   English

使用 Autofixture 创建 object 时可以只指定其中一个参数吗? (C# XUnit & Autofixture)

[英]Possible to specify just one of the parameters when creating object using Autofixture? (C# XUnit & Autofixture)

I have a complex object from a library I need a mock of that takes multiple parameters in the constructor, one of them is an enum, unfortunately我有一个来自库的复杂 object 我需要一个在构造函数中采用多个参数的模拟,不幸的是其中一个是枚举

_fixture.Create<MyObject>() 

is failing because the default enum it chooses as a parameter isn't allowed失败,因为它选择作为参数的默认枚举是不允许的

is there a way to specify which enum to use in the constructor when generating objects?有没有办法在生成对象时指定在构造函数中使用哪个枚举?

You can use.Build instead of.Create.您可以使用.Build 而不是.Create。

So something like:所以像:

fixture.Build<MyObject>().With(t=>t.MyEnum, Enum.SomeValue).Create()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM