CRM Software Logo

A panel of Microsoft Dynamics CRM/Dynamics 365 experts provide reviews and opinions to aid professionals with the CRM selection process.

 
 
Beringer Associates - Microsoft CRM Experts

Unit Testing in CRM 2016 with FakeXrmEasy – Deep Dive

Email | Print

Here at Beringer, we take great pride in developing exceptional software to create impactful solutions for our customers.  One common practice among developers, is the use of Unit Testing.  Testing software allows us to run our application locally and verify it can perform the required tasks before deploying it into an operating environment.  This method allows developers to write tests for each specification of the software to check the features of the software when changes are made.  Recently I wrote an article on XRMFakeEasy as a Testing Framework for CRM applications.  Today, I’d like to show you an example of how I used the framework to test a Custom Plugin I developed.

 

 

A Real Unit Test In Use!

I was tasked to create a custom plugin that creates a copy of an Opportunity.  This copy was to contain all of the same information on the Opportunity.  I ran a test against the compiled Workflow to verify the Opportunity fields matched the Primary Opportunity.  Below are some code samples from my test

unit

 

 

To break the testing code down, I first create a parent Customer and Owner for the Workflow.  Then, I list some fields and values inside of a Dictionary Object.  I will loop through this collection to initialize and verify defined fields have been created on the resulting Opportunity.  After placing the pre-defined values into the Opp, I call the fake Organization Service to create my Primary Opportunity.

 

The next step is to run my custom plugin using my Primary Opportunity as a Target.  The Unit Testing and FakeXRMEasy framework are set up against my custom workflow to make sure that it can run against the fake Organization Service.

 

Once the custom plugin completes, I’m using a FetchXML statement to find the Opportunity that does not equal my initial Opportunity (there should only be two Opportunities in the system, my Primary Opportunity and the Copy).  Finally, for each pre-defined Opportunity Attribute, I Assert that the Copy Opportunity values match the Primary values.

 

 

Another implementation

Luckily my Custom Plugin passed my Unit Testing!  Something I would be looking forward to in FakeXRMEasy would be support for EntityMetadata Requests.  In a previous incarnation of this test, I planned to retrieve all Opportunity Fields that could be updated on creation of an Opportunity and test the Plugin against those fields.  Check out my sample below

 

unit

 

 

My plan was to cycle through all Metadata that is eligible to be updated on a Create Request.  This would save some time and pull all fields added to the Opportunity rather than having to update the Test every time a field is created.  However, since FakeXRMEasy does not currently support EntityMetadata requests, I will have to specify my fields that I want to verify.

 

So, I’d say my experience with the FakeXRMEasy Framework was a success!  However there are plenty of features that are in the works for them.  Please contribute to their project and help make Unit Testing a regular practice in the CRM Developer Community

 

Beringer Associates a leading Microsoft Gold Certified Partner specializing in Microsoft Dynamics CRM and CRM for Distribution. We also provide expert Managed IT Services, Backup and Disaster Recovery, Cloud Based Computing and Unified Communication Systems.

Ask This Expert a Question / Leave a Comment

 

 
 
Show Buttons
Hide Buttons