0
votes

we have a azure mobile service implemented for one cross platform mobile app. We have used azure mobile services to expose the back end to mobile apps.

All the controllers we are using extending table controller and most of the service methods has some custom logic implemented. Now we wanted to unit test these custom logic.

Is there any way we can mock table controllers and write unit tests? I have tried everywhere and even i have checked MSDN forums also. I could n't get any info about it. Let me know, if anyone done this and can share a sample.

1
Azure Mobile Service is just a web api sugar coated with some additional features. I don't see why you can't use web api unit testing approach. asp.net/web-api/overview/testing-and-debugging/… - beast
its working perfectly if i use custom ApiController. But we have controllers of type TableControllers which is not allowing me to it. Because it is looking for a ApiService which i couldn't mock it :( - Dinesh

1 Answers

1
votes

All the interactions with the backend database are done through the DomainManager, so you are likely to have to moch the EntityDomainManager that you use in your TableControllers when testing. The SDK has a ctor overload for TableController that takes a DomainManager. You could register your mock with Autofac in your tests and have that get used during testing (if you are testing the full pipeline). If you are hitting the TableController in isolation with new YourController(), you can just use that overload to pass in your mocked DomainMAnager and make sure you don't create a real DomainManager in Initialize.