【发布时间】:2022-12-14 02:19:14
【问题描述】:
我有以下课程:
public class Foo
{
public Foo(string id,
string name,
string? homeTown = null,
IEnumerable<string>? someCollection = null)
{
Id = id;
Name = name;
HomeTown = homeTown;
SomeCollection = someCollection;
}
public string Id { get; set; }
public string Name {get; set;}
public string? HomeTown {get; set;}
public IEnumerable<string>? SomeCollection {get; set;}
}
我想在不填充 HomeTown 和 SomeCollection 的情况下使用 AutoFixture 创建模拟。
但是当我尝试像这样创建它时,属性仍然会被填充!
Fixture fixture = new Fixture();
var dto = fixture.Build<Foo>()
.Without(x => x.HomeTown)
.Without(x => x.SomeCollection)
.Create();
如果我添加另一个没有 hometown 和 somecollection 的构造函数 - 它会起作用,但我不想添加另一个构造函数只是为了满足测试。
为什么会出现这种行为?这是 AutoFixture 中的某种错误吗?
有办法解决吗?
【问题讨论】:
标签: c# autofixture