我有一个结构,例如:
public struct Foo
{
public int Bar;
public string Baz;
}
Run Code Online (Sandbox Code Playgroud)
并希望使用自动混合在我的单元测试中创建它.我尝试使用以下内容:
IFixture fixture = new Fixture();
var f = fixture.CreateAnonymous<Foo>();
Run Code Online (Sandbox Code Playgroud)
但这会引发AutoFixture was unable to create an instance
错误.是否可以使用自动混合自动创建结构?怎么可以这样做?请注意,我正在处理遗留代码,因此需要处理结构.:)
编辑:
变
IFixture fixture = new Fixture().Customize(new AutoMoqCustomization());
Run Code Online (Sandbox Code Playgroud)
至
IFixture fixture = new Fixture();
Run Code Online (Sandbox Code Playgroud)
因为它与这个问题无关.
如何为float,double和decimal修改AutoFixture create方法,以便在创建这些类型时它们还有一个余数?
目前我这样做,但这引发了异常.
var fixture = new Fixture();
fixture.Customize<double>(sb => sb.FromFactory<double>(d => d * 1.33)); //This should add remainder
var value = fixture.Create<double>();
Run Code Online (Sandbox Code Playgroud) 我有一个深层嵌套的对象模型:
public class CheatSheet {
public string Leader { get; set; }
public List<Section> Sections { get; set; }
}
public class Section {
public string Title { get; set; }
public List<SubSection> SubSections { get; set; }
}
public class SubSection {
public string Title { get; set; }
public List<Cheat> Cheats { get; set; }
}
public class Cheat {
public string Affected { get; set; }
public string Text { get; set; }
public string Hint { …
Run Code Online (Sandbox Code Playgroud)