Understanding FakeXrmEasy Test Flow in Dynamics 365 CRM
Why We Add Entities to MergeSalesOrdersBase When writing unit tests for Dynamics 365 CRM plugins using FakeXrmEasy, one of the most confusing concepts is: Why do we need to add entities into _entities when we already use .ToEntityReference() ? This article explains the complete testing flow step by step. The Real Problem Suppose you have a Sales Order: var salesOrder = new SalesOrder { new_ContosoSalesOrderType = ContosoSalesOrderTypes . AcknowledgementTrue . ToEntityReference () }; At first glance, it feels like the Sales Order Type already exists. But internally, that is NOT true. .ToEntityReference() only stores: Logical Name GUID Example: new_contososalesordertype GUID = 12345 It does NOT store the actual entity fields. So fields like: new_AllowSalesOrderAcknowledgments new_AllowMerging new_AllowSubstitutes are NOT available unless the entity itself is added into FakeXrmEasy. Understanding the Complete Test Flow Step 1 — Base Class Runs First Your test inher...