【问题标题】:Unit test mock interface and need convert original interface?单元测试模拟接口,需要转换原始接口吗?
【发布时间】:2014-04-08 10:55:11
【问题描述】:

我在 C# 单元测试中遇到问题。当我测试一些方法时,它们需要转换原始接口。像这样:

_stubInterface1 = MockRepository.GenerateMock<Interface1>();
...
var someData = (Interface1)_stubInterface1;

然后CLR抛出异常。你有什么想法吗?

【问题讨论】:

  • 究竟是什么异常?
  • 像这样:无法将类型为“Castle.Proxies.IRepositoryProxyac1ff7ff97894e9295744bf02790b123”的对象转换为类型“DEST.Base”。
  • 那是 RhinoMocks 吗?我已经添加了适当的标签
  • 感谢您的回复。你有什么好主意吗?我不知道如何生成Mock接口并且可以恢复它...
  • 是的,那就是 RhinoMocks 3.6.1。

标签: c# unit-testing interface mocking rhino-mocks


【解决方案1】:

对不起。我的问题有错误。我的意思是:

_stubInterface1 = MockRepository.GenerateMock<Interface1>();
...
var someData = (Interface2)_stubInterface2;

解决方案:

_stubInterface1 = MockRepository.GenerateMock<Interface1,Interface2>();
...
var someData = (Interface2)_stubInterface2;

感谢所有回复和所有人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-30
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多