See*_*eer 0 .net c# unit-testing mocking autofixture
我有课Alias
。我已经将它与 Autofixture 一起使用,一切正常。然而,当我向我的类添加接口属性时,测试开始失败。
这就是我的课:
public class Alias : NotifyPropertyChanged
{
private Alias()
{
Nicks = new List<string>();
History = new History(this);
}
public IDownloader Downloader {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我在测试中使用它是这样的:
Fixture fixture = new Fixture();
var alias = fixture.Create<Alias>();
Run Code Online (Sandbox Code Playgroud)
并得到异常:
loeh.AutoFixture.ObjectCreationException:AutoFixture 无法从 Core.Helpers.IDownloader 创建实例...
我尝试通过注册接口,fixture.Register<IVKDownloader>(() => new Downloader());
但仍然收到此错误。
如果我更改此属性以使用类型而不是接口,public Downloader Downloader {get;set;}
一切都会正常工作。我该如何解决这个问题?
fixture.Register<IVKDownloader>(() => new Downloader());
看起来这是一个错字IDownloader
fixture.Register<IDownloader>(() => new Downloader());