【发布时间】:2014-11-04 05:27:11
【问题描述】:
我有一堂课Alias。我已经将它与 Autofixture 一起使用,并且一切正常。但是,当我向我的类添加接口属性时,测试开始失败。
这就是我的课:
public class Alias : NotifyPropertyChanged
{
private Alias()
{
Nicks = new List<string>();
History = new History(this);
}
public IDownloader Downloader {get;set;}
}
我在这样的测试中使用它:
Fixture fixture = new Fixture();
var alias = fixture.Create<Alias>();
并得到异常:“loeh.AutoFixture.ObjectCreationException:AutoFixture 无法从 Core.Helpers.IDownloader... 创建实例”
我已尝试通过fixture.Register<IVKDownloader>(() => new Downloader()); 注册接口,但我仍然收到此错误。
如果我将此属性更改为使用类型而不是接口public Downloader Downloader {get;set;},则一切正常。我该如何解决这个问题?
【问题讨论】:
-
您为什么认为
fixture.Register<IVKDownloader>会影响IDownloader的创建方式? -
这是
IVKDownloader的拼写错误,而不是IDownloder?如果不是,那可能就是它不起作用的原因 -
@John 是的,谢谢,这解决了问题。
-
@Seekeer 好的,我会添加它作为答案,很高兴它的工作! :)
标签: c# .net unit-testing mocking autofixture