开发者

Mocking a Microsoft DLL

开发者 https://www.devze.com 2023-02-16 20:27 出处:网络
I have an application that references a Microsoft DLL (Exchange Web Services). In my unit testing, I want to replace the Microsoft DLL with a Mock.

I have an application that references a Microsoft DLL (Exchange Web Services). In my unit testing, I want to replace the Microsoft DLL with a Mock.

What works with other DLLs, doesnt work with this DLL, as i get an exception

The located ass开发者_开发问答embly's manifest definition does not match the assembly reference

I verified it has the same assembly version, but i saw that the Microsoft DLL is signed digitally, so it has a PublicKeyToken. Could this be what my Application is looking for? A similarly signed DLL?

Is there a way of referencing a DLL without requiring its publickeytoken?

Thanks


You can't mock a signed DLL. (If you could you will be hired by mafia...)

Mock the code that accesses code in this dll.

Create a facade (if you don't have it), that wraps access to methods in Exchange dll. Then in your tests you can provide a mock facade.

It is a good design practice to shield your code from any third-party code (assemblies, web services, control) by the means of facades / wrappers. This minimizes the risk of impact should the third party code change, ie. upgrading to a newer version of dll (the required changes will affect only the facade) and help with testing.

0

精彩评论

暂无评论...
验证码 换一张
取 消