Tutorial 2 - phuocle/Dynamics-Crm-DevKit GitHub Wiki
Task
- Create Unit Test Plugin
Prerequisites
- Finish Tutorial 1
Coding
- Add
New Project09. C# ProxyTypes Projectto your solution- A popup form
Add new Proxy Types Projectopened - Click button
><to create/select a Dynamics 365 connection - After connected, click
OK PL.DynamicsCrm.DevKitcreated project name:Paz.LuckeyMonkey.ProxyTypes
- A popup form
- Rebuild solution to restore
NuGetpackages Execute Filerun.batofPaz.LuckeyMonkey.ProxyTypesproject, waitingCrmSvcUtilgenerate code toGeneratedCode.csfile.- Rebuild solution without errors
- Add
New Project06. C# Test Projectto your solution- A popup form
Add new Test Projectopened - Dropdown list all available projects test
- Select
Paz.LuckeyMonkey.Plugin.Lead - Select
9.0.2.4in theCrm VersionPL.DynamicsCrm.DevKitget allMicrosoft.CrmSdk.CoreAssembliesversion fromNuGet - Select
4.5.2in the.Net version - Click
OK PL.DynamicsCrm.DevKitcreated test project name:Paz.LuckeyMonkey.Plugin.Lead.Test
- A popup form
- Rebuild solution to restore
NuGetpackages - Add
New Item05. C# Test ClasstoPaz.LuckeyMonkey.Plugin.Lead.Testproject- A popup form
Add new Test CLassopened - Dropdown list all available test class
- Select
PreLeadCreateSynchronous - Click
OK PL.DynamicsCrm.DevKitcreated test class:PreLeadCreateSynchronousTest
- A popup form
- Rebuild solution without errors
- Open
Test Explorerwindow andRun Alltests.- 4 passed tests.
- 1 failed test.
- Edit failed test
[TestMethod]
public void PreLeadCreate_LeadSubjectAlwaysUppercase()
{
//setup
Context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(ProxyTypesAssembly));
Context.Data.Clear();
var subject = "lowcase subject";
var target = new Entity("lead")
{
["leadid"] = Guid.NewGuid(),
["subject"] = subject
};
PluginContext.InputParameters["Target"] = target;
//run
Context.ExecutePluginWithConfigurations<PreLeadCreateSynchronous>(PluginContext, null, null);
//result
var resultTarget = (Entity)PluginContext.InputParameters["Target"];
var lead = new Shared.Entities.Lead(resultTarget);
Assert.AreEqual(subject.ToUpper(), lead.Subject, false);
}
Run Alltests again- 5 passed tests
- Check-in all files to your source control
- You finished this tutorial
Summary
This tutorial, you know howto