如何测试在C#中的COM依赖对象 [英] How to test a COM dependent object in C#

查看:210
本文介绍了如何测试在C#中的COM依赖对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试做TDD与具有一个COM接口的依赖的对象。我虽然对嘲讽COM接口,同时做开发测试,并做实时的集成测试。

I´m trying to do TDD with an object that has a dependency on a COM Interface. I though about mocking the COM interface, while doing development testing, and do it real on the integration tests.

不过,我不能嘲笑COM接口,我试着用起订量,和它抛出一个异常:

However, I cannot mock the COM interface, I tried with Moq, and it throws an exception:

System.TypeLoadException是由用户代码
未处理的讯息
=无法加载类型从程序集Castle.Proxies.iTunesAppProxy'
'DynamicProxyGenAssembly2,
版= 0.0.0.0,文化=中立,
公钥=空'。类型是
标记为类型
等价为合格,但无论是它具有通用
参数,或者它不是一个结构,
COM导入接口,枚举
或委派

System.TypeLoadException was unhandled by user code Message=Could not load type 'Castle.Proxies.iTunesAppProxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The type is marked as eligible for type equivalence, but either it has generic parameters, or it is not a structure, COM imported interface, enumeration, or delegate

是否有可能与其他框架?
你怎么做TDD与COM依赖对象?

Is it possible with other frameworks? How do you do TDD with COM dependent objects?

谢谢!或委派

推荐答案

我建议您采取COM对象的接口的所有权,这是哪里的依赖倒置原则将开始发挥作用。

I would suggest that you take ownership of the interface of the COM object, this is where Dependency Inversion Principle would come into play.

如果你没有访问源,你必须创建自己的抽象,封装了COM对象,否则就会在你的代码的第三方电话。

If you don't have access to the source, you will have to create your own abstraction that wraps the COM Object, otherwise you will have third-party calls throughout your code.

现在的抽象应该可以被嘲笑。包装的实际执行情况将有COM对象为 HAS-A 关系。

Now the abstraction should be able to be mocked. The actual implementation of the wrapper will have the COM object as a HAS-A relationship.

您会再想有对执行情况的集成测试。

You will then want to have an integration test for the implementation.

您需要把COM对象本身,如果它是类似于数据库或图形渲染引擎或Web服务的东西。

You need to treat the COM object itself as if it was something similar to a database or graphic rendering engine or a web service.

这篇关于如何测试在C#中的COM依赖对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆