Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to Mock the Microsoft Exchange Web Service

I'm trying to test my application, which is using the Microsoft Exchange Web Service dll to access an Exchange Server.

I want to isolate my application from a need for an actual Exchange Server in my tests, and i realized i cannot mock the Exchange DLL...

Another problem, is that i cannot change the operational code, which does not use an interface or an adapter to access the Exchange Web Service DLL, therefore i cannot simply stub it...

In my research i found the Microsoft Moles framework, which allows me to Mole and replace any method (even constructors) with my own delegate. However, i found that in the application code, we're using internal Microsoft data types (for example EmailMessage) that do not allow much freedom of how to create them or change them.

Does anybody have any suggestions as to what i can do in such a situation?

Thanks.

like image 427
Yiftach Tzur Avatar asked Nov 29 '25 22:11

Yiftach Tzur


1 Answers

If i where you i would try to hide exchange behind an email service facade and replace all code that is directly referenceing exchange with calls to that facade.

Mockin the facade is much easier than mocking exchange itself.

As a sideeffect if customer decides to use some other email system you just have to reimplement the facade instead of changing the whole application.

like image 175
k3b Avatar answered Dec 01 '25 12:12

k3b



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!