mjacobsen4DFM / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

Make mocking easier by specifiying virtual on appropriate methods in the library #392

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
External references, such as a standards document, or specification?
https://code.google.com/r/iancox-google-api-dotnet-client/source/list

Target platform (e.g. Windows, Mono, Silverlight, WP7, All)?
All

Please describe the feature requested.
Mocking can be tricky at times because quite a lot of the api classes do not 
have virtual methods. So far this has affected me in the ResumableUpload and 
ClientServiceRequest classes. I am sure there are other places where a 
judicious use of virtual will be helpful.

I've made changes in my own clone (see above) so you can see what I mean.

Original issue reported on code.google.com by ian....@releaseconsulting.co.uk on 24 Sep 2013 at 2:33

GoogleCodeExporter commented 9 years ago
For mocking purposes you may want to use the interface (IClientServiceRequest) 
for example and not changing the methods to be virtual.

Original comment by pele...@google.com on 25 Sep 2013 at 12:06

GoogleCodeExporter commented 9 years ago
Can you advise how I can inject a mock IClientServiceRequest into the google 
drive sdk library?
For example I want to mock ChangesResource.ListRequest so that when I call 
Execute I get my fake ChangeList response.

To this end I have a mock DriveService that returns a mock ChangesResource from 
DriveService.Changes.

My mock changes resource reutrns a mock ChangesResource.ListRequest (this 
ultimately inherits from IClientServiceRequest) but is of type 
ChangesResource.ListRequest. It's because I am mocking 
ChangesResource.ListRequest that I need to be able override the Execute method .

Is there a different way where I can just use the mock IClientServiceRequest 
then. Perhaps using the Initializer?

Original comment by ian....@releaseconsulting.co.uk on 25 Sep 2013 at 8:39

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 12 Dec 2013 at 3:41