Answered by:
Interface.

Question
-
Hi,
Can I create a instance of interface in MS CRM ? Example, Execute(IPluginExecutionContext context) is used during developing a custom plugin.
Wednesday, January 12, 2011 9:38 AM
Answers
-
Are you talking about trying to instantiate an object that implements the IPluginExecutionContext interface; presumably for the purposes of unit testing a plugin?
If so; no, you can't do it correctly. However, you can unit test your plugins by "Mocking" the interface; using a mocking framework, such as RhinoMocks or Microsoft's own Moles, you can create mocking objects through which calls to an instance of an interface such as IPluginExecutionContext can be routed to implementations that you provide
I've used this strategy via RhinoMocks to build a flexible Plugin unit testing framework. See the following blog postings for examples of how to do the same (one uses RhinoMock; the other, NMock):
http://www.luisrocha.net/2009/06/unit-testing-crm-plug-ins.html
http://stateracrm.blogspot.com/2008/07/tdding-crm-40-plugin.html
--pogo (pat)- Marked as answer by Donna EdwardsMVP Wednesday, January 19, 2011 11:46 PM
Thursday, January 13, 2011 6:07 AM -
1st of all as per OOPS u can not instantiate or create an Interface.
as you have told " Execute(IPluginExecutionContext context)"
this is handled by the crm frame work and the context is not instantiated as IPluginExecutionContext. It has created as the sub class of something which has inheritaed from IPluginExecutionContext and assogned to the super class IPluginExecutionContext .
hope this claryfies you. else put ur query bit clear.
yes.sudhanshu
http://bproud2banindian.blogspot.com
http://ms-crm-2011-beta.blogspot.com- Marked as answer by Donna EdwardsMVP Wednesday, January 19, 2011 11:46 PM
Thursday, January 13, 2011 7:31 AM -
You might like to read up on Interfaces on MSDN aswell http://msdn.microsoft.com/en-us/library/87d83y5b(v=vs.80).aspx
MSCRM Bing'd - http://bingsoft.wordpress.com Check out the CRM 4 to CRM 2011 JavaScript Converter Tool CRM Forum Guidance on how to Help Us Help You - Marked as answer by Donna EdwardsMVP Wednesday, January 19, 2011 11:45 PM
Friday, January 14, 2011 10:30 AMModerator
All replies
-
Can you explain more about what your trying to do please?
MSCRM Bing'd - http://bingsoft.wordpress.com Check out the CRM 4 to CRM 2011 JavaScript Converter Tool CRM Forum Guidance on how to Help Us Help You Wednesday, January 12, 2011 12:41 PMModerator -
Actually in C# we can't create the instance of a interface .But while we are creating plugins, we create a instance ( object in oop language) of a interface ,for eg: Execute(IPluginExecutionContext context) this method used for creating plugin.So I just want to clarify how can we create a instance of a Interfa
Thursday, January 13, 2011 4:54 AM -
Are you talking about trying to instantiate an object that implements the IPluginExecutionContext interface; presumably for the purposes of unit testing a plugin?
If so; no, you can't do it correctly. However, you can unit test your plugins by "Mocking" the interface; using a mocking framework, such as RhinoMocks or Microsoft's own Moles, you can create mocking objects through which calls to an instance of an interface such as IPluginExecutionContext can be routed to implementations that you provide
I've used this strategy via RhinoMocks to build a flexible Plugin unit testing framework. See the following blog postings for examples of how to do the same (one uses RhinoMock; the other, NMock):
http://www.luisrocha.net/2009/06/unit-testing-crm-plug-ins.html
http://stateracrm.blogspot.com/2008/07/tdding-crm-40-plugin.html
--pogo (pat)- Marked as answer by Donna EdwardsMVP Wednesday, January 19, 2011 11:46 PM
Thursday, January 13, 2011 6:07 AM -
1st of all as per OOPS u can not instantiate or create an Interface.
as you have told " Execute(IPluginExecutionContext context)"
this is handled by the crm frame work and the context is not instantiated as IPluginExecutionContext. It has created as the sub class of something which has inheritaed from IPluginExecutionContext and assogned to the super class IPluginExecutionContext .
hope this claryfies you. else put ur query bit clear.
yes.sudhanshu
http://bproud2banindian.blogspot.com
http://ms-crm-2011-beta.blogspot.com- Marked as answer by Donna EdwardsMVP Wednesday, January 19, 2011 11:46 PM
Thursday, January 13, 2011 7:31 AM -
Ya I got it. You are telling that some class has implemented IPluginExecutionContext interface, and we are creating intsance of that class( i mean instance of implemented class and refering that object by Base class).Is it so?..
Thanks for your reply.
Help me in future also ,if possible.
Thursday, January 13, 2011 10:29 AM -
Thank you for your reply.Thursday, January 13, 2011 10:32 AM
-
Ya I got it. You are telling that some class has implemented IPluginExecutionContext interface, and we are creating intsance of that class( i mean instance of implemented class and refering that object by Base class).Is it so?..
Thanks for your reply.
Help me in future also ,if possible.
yes, what you got is what i mean.you are right.
and definitely in future. :)
yes.sudhanshu
http://bproud2banindian.blogspot.com
http://ms-crm-2011-beta.blogspot.comFriday, January 14, 2011 6:12 AM -
Ya I got it. You are telling that some class has implemented IPluginExecutionContext interface, and we are creating intsance of that class( i mean instance of implemented class and refering that object by Base class).Is it so?..
Thanks for your reply.
Help me in future also ,if possible.
yes, what you got is what i mean.you are right.
definitely in future.
yes.sudhanshu
http://bproud2banindian.blogspot.com
http://ms-crm-2011-beta.blogspot.comFriday, January 14, 2011 6:13 AM -
You might like to read up on Interfaces on MSDN aswell http://msdn.microsoft.com/en-us/library/87d83y5b(v=vs.80).aspx
MSCRM Bing'd - http://bingsoft.wordpress.com Check out the CRM 4 to CRM 2011 JavaScript Converter Tool CRM Forum Guidance on how to Help Us Help You - Marked as answer by Donna EdwardsMVP Wednesday, January 19, 2011 11:45 PM
Friday, January 14, 2011 10:30 AMModerator