locked
Unit Testing with EWS Managed API RRS feed

  • Question

  • Hi,

    I've just started looking at the new EWS Managed API and so far have found it vastly easier to use than the generated web service proxy classes.  However, I'm now looking to add some unit tests for the managing of subscriptions and processing of notifications.  In order to do that I was hoping to be able to mock out the ExchangeService class and use my mock service to return a dummy PushSubscription, EmailMessage etc from an in memory cache of objects.  This is proving to be extremely problematic however as many of the objects I require have only internal constructors and rely on static factory methods for construction and a conncrete implementation of the ExchangeService class (eg the PushSubscription class).  Now, I could jump through hoops and use reflection to try and construct some of these objects, but I'd obviously prefer not to have to go down that route so I just wonder if anyone has successfully managed to mock out the ExchangeService class?

    Thanks in advance,

    Graham
    Thursday, August 27, 2009 2:47 PM

Answers

  • Hi,

    I usually don't call the managed API directly from my application. Instead I always encapsulates the whole stuff in a connector class that exposes the methods I need. I required, I also encapsulate the response returned from the Exchange service. This way I can decouple my application from the ExchangeServiceBinding. This way you can unittest your application by mocking that ExchangeConnector class.

    Kind regards,
    Henning Krause
    • Marked as answer by gmancoll Wednesday, October 7, 2009 3:04 PM
    Thursday, August 27, 2009 7:05 PM

All replies

  • Hi,

    I usually don't call the managed API directly from my application. Instead I always encapsulates the whole stuff in a connector class that exposes the methods I need. I required, I also encapsulate the response returned from the Exchange service. This way I can decouple my application from the ExchangeServiceBinding. This way you can unittest your application by mocking that ExchangeConnector class.

    Kind regards,
    Henning Krause
    • Marked as answer by gmancoll Wednesday, October 7, 2009 3:04 PM
    Thursday, August 27, 2009 7:05 PM
  • Henning's approach is what we recommend.
    David Claux | Program Manager - Exchange Web Services
    Thursday, August 27, 2009 7:59 PM
  • Hi,

    thanks for that, that makes a lot of sense.  So I take it you define your own types which correspond to the types returned by the Exchange Service call and simply copy the values you require from the Managed API types?

    Thanks,

    Graham
    Friday, August 28, 2009 7:58 AM
  • You can go as far as you'd like/need to suit your testing requirements, which can include defining your own types to wrap around the the API's. The key is really to introduce an intermediate layer that you own and that you can "fake".
    David Claux | Program Manager - Exchange Web Services
    Friday, August 28, 2009 3:32 PM