I'm attempting to refactor my code so that I can unit test using fakexrmeasy.
As part of the suggested refactor mentioned here, I've attempted to pass IOrganizationService into all of my classes and methods. However, some of my classes use variables and methods that IOrganizationService doesn't have, such as Timeout. I'm trying to find a way to refactor to use IOrganizationService without losing functionality.
This is how it exists before refactoring.
class testClass () {
public void testMethod(OrganizationServiceProxy service) {
service.Timeout = new TimeSpan(0, 15, 0);
}
}
This is after the refactor. I've tried casting IOrganizationService to OrganizationServiceProxy, but the faked service context can't handle this cast. An exception is thrown.
class testClass () {
public void testMethod(IOrganizationService service) {
var serviceProxy = (OrganizationServiceProxy) service; //This breaks when given a fake context
service.Timeout = new TimeSpan(0, 15, 0);
}
}
I've tried using an IOrganizationServiceFactory, as suggested in this post. The problem is, factory.CreateOrganizationService() generates an IOrganizationService, not an OrganizationSeriviceProxy.
How can I refactor to use IOrganizationService instead of OrganizationServiceProxy without losing functionality? I'm guessing I might have to implement the IOrganizationService as an OrganizationServiceProxy somehow.