繁体   English   中英

自动固定不能与接口属性一起使用?

[英]Autofixture couldnt work with interfaces properties?

我有一个类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());注册接口fixture.Register<IVKDownloader>(() => new Downloader()); 但我仍然收到此错误。

如果我将此属性更改为使用type而不是接口public Downloader Downloader {get;set;}一切正常。 我该如何解决?

fixture.Register<IVKDownloader>(() => new Downloader()); 看起来这是IDownloader的错字

fixture.Register<IDownloader>(() => new Downloader());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM