Skip to content

Tutorial 9

PhuocLe edited this page Mar 8, 2018 · 12 revisions

Task

  • Update Unit Test project for plugin: Wooow.Kool.Plugin.Account

Coding

This is your exercise.

[TestMethod]
public void PostAccountCreate_Test_Create_Contact()
{
    //setup
    Context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(ProxyTypesAssembly));
    Context.Data.Clear();
    var ACCOUNT_ID = Guid.Parse("{A7EF9A9B-F878-4CD1-B7BB-30470D60FDB7}");
    var target = new Shared.Entities.Account
    {
        AccountId = ACCOUNT_ID,
        Name = "Account Name",
        Telephone1 = "12345678"
    };
    PluginContext.InputParameters["Target"] = target.GetCreateEntity();

    //run
    var plugin = Context.ExecutePluginWith<PostAccountCreateSynchronous>(PluginContext);

    //result
    var fetchData = new
    {
        parentcustomerid = ACCOUNT_ID
    };
    var fetchXml = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
  <entity name='contact'>
    <attribute name='contactid'/>
    <attribute name='parentcustomerid'/>
    <attribute name='address1_addresstypecode'/>
    <attribute name='telephone1'/>
    <attribute name='firstname'/>
    <order attribute='parentcustomerid' descending='false'/>
    <filter type='and'>
      <condition attribute='parentcustomerid' operator='eq' value='{fetchData.parentcustomerid}'/>
    </filter>
  </entity>
</fetch>
";
    var rows = Context.GetFakedOrganizationService().RetrieveMultiple(new FetchExpression(fetchXml));
    if (rows.Entities.Count != 1)
        Assert.Fail("Not found contact record");
    var contact = new Shared.Entities.Contact(rows.Entities[0]);
    Assert.AreEqual("Account Name", contact.FirstName);
    Assert.AreEqual("12345678", contact.Telephone1);
    Assert.AreEqual(ACCOUNT_ID, contact.ParentCustomerId.Id);
    Assert.AreEqual(Address1_AddressTypeCode.Other, contact.Address1_AddressTypeCode);
}

Your Solution Explorer after you finished this tutorial

Finished Tutorial 9

Clone this wiki locally