首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FakeItEasy异常方法没有实现

FakeItEasy异常方法没有实现
EN

Stack Overflow用户
提问于 2018-06-18 07:47:49
回答 1查看 469关注 0票数 0

我有一个普通的单元测试,并试图在安装方法中创建一个假接口:

代码语言:javascript
复制
[TestInitialize]
    public void Setup()
    {
        var unityContainer = A.Fake<IUnityContainer>();

        var addTagAction = A.Fake<IAddTagAction>();

        A.CallTo(() => unityContainer.Resolve(typeof(IAddTagAction), null, A<ResolverOverride[]>._)).Returns(addTagAction);

        this.testee = new ActionFactory(unityContainer);
    }

不幸的是,在行var addTagAction = A.Fake<IAddTagAction>();上,我得到了以下异常:

'Argus.Avenue.DataService.Test.Regeln.ActionFactoryTest.Setup‘hat eine Ausnahme ausgel st.Argus.Avenue.Data.DataService.Regeln.Actions.IAddTagAction.:未能创建类型为FakeItEasy.Core.FakeCreationException的伪 下面列出了每个尝试构造函数失败的原因:没有构造函数参数失败:在Argus.Avenue.Data.DataService.Regeln.Actions.IAddTagAction.类型上找不到可用的默认构造函数在此调用过程中捕获了System.TypeLoadException类型的异常。它的信息是:死卫理公会"GetWertbezeichnung“im Typ‘Castle.Proxies.ObjectProxy_1’der Assembly "DynamicProxyGenAssembly2,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null”hat。

翻译:--汇编"DynamicProxyGenAssembly2、Version=0.0.0.0、Culture=neutral、PublicKeyToken=null“中"Castle.Proxies.ObjectProxy_1”类型的方法"GetWertbezeichnung“没有实现。

下面是所涉及的接口和类:

IAddTagAction:

代码语言:javascript
复制
public interface IAddTagAction : IBaseAction
{
}

IBaseAction:

代码语言:javascript
复制
public interface IBaseAction
{
    void Execute(IList<long> artikelIds, int? id, RegelModel regelModel);
    string GetWertbezeichnung(int? wert);
    string GetWertbezeichnung(IList<int> werte);
}

AddTagAction:

代码语言:javascript
复制
public class AddTagAction : BaseAction, IAddTagAction
{
    public AddTagAction(
        IEfContextFactory efContextFactory, 
        IRepositoryFactory repositoryFactory, 
        IDateTimeProvider dateTimeProvider)
        : base(efContextFactory, repositoryFactory, dateTimeProvider)
    {
    }

    public override void Execute(IList<long> artikelIds, int? tagId, RegelModel regelModel)
    {
        // ...
    }

    /// <inheritdoc />
    public override string GetWertbezeichnung(IList<int> werte)
    {
        using (var context = this.EfContextFactory.Create(RequestInfo))
        {
            var tagRepository = this.RepositoryFactory.Create<ITagRepository>(context, RequestInfo);
            var tags = tagRepository.GetTagNames(werte.ToList()).FirstOrDefault();
            return tags.Value;
        }
    }

BaseAction:

代码语言:javascript
复制
public abstract class BaseAction : IBaseAction
{
    protected BaseAction(IEfContextFactory efContextFactory, IRepositoryFactory repositoryFactory, IDateTimeProvider dateTimeProvider)
    {
        this.EfContextFactory = efContextFactory;
        this.RepositoryFactory = repositoryFactory;
        this.DateTimeProvider = dateTimeProvider;
    }

    protected IRepositoryFactory RepositoryFactory { get; }

    protected IEfContextFactory EfContextFactory { get; }

    protected IDateTimeProvider DateTimeProvider { get; }

    public virtual void Execute(IList<long> artikelIds, int? id, RegelModel regelModel)
    {
        // ...
    }

    public string GetWertbezeichnung(int? wert)
    {
        if (!wert.HasValue) {
            return string.Empty;
        }
        var werte = new List<int> { wert.Value };
        return GetWertbezeichnung(werte);
    }

    public abstract string GetWertbezeichnung(IList<int> werte);
}
  • 为什么我在创建一个假的IAddTagAction接口时会得到这个异常呢?

提前感谢

编辑:,如果我删除"GetWertbezeichnung"-methods,伪造作品..。一定和这些方法有关..。

Edit2:我们使用的版本是:

  • 目标框架:.NET Framework 4.6.2
  • 平台目标:x64
  • FakeItEasy:4.1.1
  • MSTest.TestAdapter 1.2.0
  • MSTest.TestFramework 1.2.0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-18 09:24:18

这是已知臭虫在FakeItEasy 4.1.1中,由于Castle.Core中的一个bug。它在FakeItEasy 4.2.0中得到了修正。只要升级到一个更新的版本,你就会没事的。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50904835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档