Using the Serialized Plugin Context in Your Tests

Sep 29, 2011 at 8:50 AM

Hello,

Could you please post a sample code for using the serialized plugin context in tests?

Thanks.

Coordinator
Oct 5, 2011 at 2:11 PM

Seyfullah,

I'll try to provide some high level samples here, though it depends on what testing framework you're using and what you're trying to test. Also complicating things is that I don't actually do much work with CRM anymore, and don't have access to a CRM instance, so some of this code's syntax may be a little off.

So let's say you have a plugin named ChangeAccountStatus.

First you follow the steps in the How To Use section of the documentation to get your serialized context.

Then you write a testmethod that looks something like this

public void TestMethod()

{

var serviceProvider = MyServiceProvider (string filepath) //Note you might want to use one of the other constructors covered in the documentation depending on your scenario.

var plugin = new ChangeAccountStatus();

plugin.Execute(serviceProvider);

//Put the code containing the various things you want to assert are true as part of your test here

}

Oct 6, 2011 at 2:27 PM
Edited Oct 6, 2011 at 2:28 PM

Thank you very much :)

What I was missing was that I didn't reference My Plugin project. When I used the appropriate Plugin class. I succeeded to debug my plugin using your tool.

Oct 16, 2012 at 8:15 AM

How did you do? I still don't know how to do. :(

Oct 16, 2012 at 10:35 AM

Finally, I know how to use the tool already. :)

Jan 17, 2013 at 2:54 PM

I have problems adding a reference to my testing project. When I try

using TestPlugin;

the namespace for TestPlugin can't be found even in IntelleSense.

Coordinator
Jan 17, 2013 at 3:00 PM

Code_Researcher,

The namespace is actually Engage.Util.PluginTester

From: Code_Researcher [email removed]
Sent: Thursday, January 17, 2013 9:54 AM
To: Swerlick, Andrew
Subject: Re: Using the Serialized Plugin Context in Your Tests [crm2011plugintest:274206]

From: Code_Researcher

I have problems adding a reference to my testing project. When I try

using TestPlugin;

the namespace for TestPlugin can't be found even in IntelleSense.

Jan 17, 2013 at 3:06 PM

Thank you very much for this quick answer! :-D

I've no idea why I haven't seen this entry in IntelliSens!?