How to test a COM dependent object in C#

后端 未结 4 1213
后悔当初
后悔当初 2021-01-06 02:51

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 th

4条回答
  •  庸人自扰
    2021-01-06 03:50

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

    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.

    [EDIT]

    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.

    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.

提交回复
热议问题