Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking a Microsoft DLL

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 assembly'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

like image 903
Yiftach Avatar asked Mar 15 '11 19:03

Yiftach


1 Answers

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.

like image 101
Jakub Konecki Avatar answered Nov 15 '22 15:11

Jakub Konecki