【问题标题】:Mole Stub and AttributesMole Stub 和属性
【发布时间】:2011-11-28 10:26:33
【问题描述】:

我正在为某个方法创建一个单元测试,该方法加载由PluginAttribute 修饰的所有类型。

有没有办法在 Moles 生成的存根对象上“注入”一个属性,而不是手动创建存根并用 PluginAttribute 装饰它?

            foreach (Type t in types)
            {

                    var attr = Attribute.GetCustomAttribute(t, typeof(PluginAttribute), false) as PluginAttribute;
                    if (attr != null)
                    {
                        _checksLookup.Add(attr.ElementName, t);
                    }

                }
            }

【问题讨论】:

    标签: moles


    【解决方案1】:

    使用 Moles,您可以绕过 Attribute.GetCustomAttribute 方法,以便它在输入时获得存根类型时返回 PluginAttribute 的新实例,否则返回默认实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多