【问题标题】:Autofixture couldnt work with interfaces properties?Autofixture 不能与接口属性一起使用?
【发布时间】: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&lt;IVKDownloader&gt;(() =&gt; new Downloader()); 注册接口,但我仍然收到此错误。

如果我将此属性更改为使用类型而不是接口public Downloader Downloader {get;set;},则一切正常。我该如何解决这个问题?

【问题讨论】:

标签: c# .net unit-testing mocking autofixture


【解决方案1】:

fixture.Register&lt;IVKDownloader&gt;(() =&gt; new Downloader()); 看起来这是 IDownloader 的拼写错误

fixture.Register&lt;IDownloader&gt;(() =&gt; new Downloader());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多