diff --git a/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_DynamicSobjectUnitOfWorkTest.cls b/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_DynamicSobjectUnitOfWorkTest.cls index 62cd7071c54..61cba347ee3 100644 --- a/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_DynamicSobjectUnitOfWorkTest.cls +++ b/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_DynamicSobjectUnitOfWorkTest.cls @@ -523,6 +523,35 @@ private without sharing class ortoo_DynamicSobjectUnitOfWorkTest ortoo_Asserts.assertContains( 'SObject type Contact is invalid for publishing within this unit of work', exceptionMessage, 'registerPublishAfterFailureTransaction, when called with a non event, will throw an exception' ); } + @isTest + private static void onCommitWorkStarting_whenCalled_setsTheOrderOfTheOperations() // NOPMD: Test method name format + { + Opportunity opportunityRecord = new Opportunity( Name = 'test' ); + Contact contactRecord = new Contact( LastName = 'test' ); + Account accountRecord = new Account( Name = 'test' ); + + Test.startTest(); + + ortoo_DynamicSobjectUnitOfWork uow = new ortoo_DynamicSobjectUnitOfWork(); + + uow.registerNew( opportunityRecord ); + uow.registerNew( contactRecord ); + uow.registerNew( accountRecord ); + + uow.registerRelationship( contactRecord, Contact.AccountId, accountRecord ); + uow.registerRelationship( opportunityRecord, Opportunity.AccountId, accountRecord ); + + uow.onCommitWorkStarting(); + + Test.stopTest(); + + List expected = new List{ + Account.sobjectType, Contact.sobjectType, Opportunity.sobjectType + }; + + System.assertEquals( expected, uow.m_sObjectTypes, 'onCommitWorkStarting, when called, will set the order of operations' ); + } + @isTest private static void commitWork_whenGivenCircularReferences_throwsAnException() // NOPMD: Test method name format {