3
我有表达下面的代码以声明的方式麻烦:Autofixture:如何以声明方式表示下列代码?
[Theory]
[InlineData(@"-o=C:\Temp\someFile -p=1")]
[InlineData(@"-p=1 -o=C:\Temp\someFile")]
public void ParseMissingParameterShouldReturnCorrectResult(
string argsString
)
{
.....
var fixture = new Fixture();
fixture.Register<IFoo>(fixture.Create<Foo>);
fixture.Register<IBar>(fixture.Create<Bar>);
var sut = fixture.Create<SomeClass>();
.....
}
在我的生产代码,我有这样的:
new SomeClass(new Foo(new Bar))
与SomeClass的的构造函数定义为:
public SomeClass(IFoo foo)
TIA,
大卫
编辑:
SomeClass的看起来像
public class SomeClass : IQux
{
private readonly IFoo _foo;
public SomeClass(IFoo foo)
{
_foo= foo;
}
不幸的是,这不是在我的情况下工作,因为我得到以下异常:'Ploeh.AutoFixture.Objec tCreationException:AutoFixture无法从nameSpace.IFoo创建实例,很可能是因为它没有公共构造函数,是抽象类型或非公共类型。唯一的区别是我使用FakeItEasy。 – DavidS 2013-04-22 11:48:28
'SomeClass'类型是怎么样的?你可以更新原始答案吗?.. – 2013-04-22 12:18:50
如果你使用的是FakeItEasy,只需用'AutoFakeItEasyCustomization'代替'AutoMoqCustomization'。还要注意,提供的示例使用“InlineAutoMockData”(而不是内置的InlineData或InlineAutoData)。 – 2013-04-22 12:23:04