Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit test to reproduce the issue #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,54 @@ public class DomainProcessInjectionTest
}
}



@isTest
private static void whenTriggerFiredMultipleTimeThenClassToInjectNotRecursiveIfNeeded() {
List<DomainProcessBinding__mdt> config = new List<DomainProcessBinding__mdt> {
new DomainProcessBinding__mdt(
Label = 'PreventRecursiveInTriggerCriteria',
ClassToInject__c = 'DomainProcessInjectionTest.PreventRecursiveInTriggerCriteriaTest',
IsActive__c = true,
OrderOfExecution__c = 100853107.10,
ProcessContext__c = 'TriggerExecution',
RelatedDomainBindingSObject__c = 'Account',
TriggerOperation__c = 'Before_Update',
ExecuteAsynchronous__c = false,
Type__c = 'Criteria',
PreventRecursive__c = true
),

new DomainProcessBinding__mdt(
Label = 'PreventRecursiveInTriggerAction',
ClassToInject__c = 'DomainProcessInjectionTest.PreventRecursiveInTriggerActionTest',
IsActive__c = true,
OrderOfExecution__c = 100853107.10,
ProcessContext__c = 'TriggerExecution',
RelatedDomainBindingSObject__c = 'Account',
TriggerOperation__c = 'Before_Update',
ExecuteAsynchronous__c = false,
Type__c = 'Action',
PreventRecursive__c = true
)

};


DomainProcessCoordinator.setMockDomainProcessBindings(config);

List<Account> accList = new List<Account> {
new Account(Name='Test', Id = fflib_idgenerator.generate(Account.SObjectType) )
};
fflib_SObjectDomain.Test.Database.onUpdate(accList, new Map<Id, SObject>(accList));
fflib_SObjectDomain.triggerHandler(DomainProcessInjectionTest.AccountsTestDomainConstructor.class);
fflib_SObjectDomain.triggerHandler(DomainProcessInjectionTest.AccountsTestDomainConstructor.class);

List<SObject> result = DomainProcessInjectionTest.lastConstructed.getRecords();
System.Assert.areEqual('Test&', ((Account) result[0]).Name, 'Account Name should have been modified only once');

}

public with sharing class AccountsTestDomain
extends ApplicationSObjectDomain
{
Expand Down Expand Up @@ -449,6 +497,39 @@ public class DomainProcessInjectionTest
}
}

public class PreventRecursiveInTriggerCriteriaTest implements IDomainProcessCriteria
{
private list<Account> records = new list<Account>();

public IDomainProcessCriteria setRecordsToEvaluate(List<SObject> records)
{
this.records.clear();
this.records.addAll( (list<Account>)records );

return this;
}

public List<SObject> run()
{
return this.records;
}
}

public class PreventRecursiveInTriggerActionTest extends DomainProcessAbstractAction
{
public override void runInProcess()
{
Account accountRecord = null;

for ( SObject record : this.records )
{
accountRecord = (Account)record;
accountRecord.Name = accountRecord.Name+'&';
DomainProcessInjectionTest.processedRecords.add(accountRecord);
}
}
}

public static final ApplicationSObjectUnitOfWork applicationSObjectUOW=
new ApplicationSObjectUnitOfWork(
new List<Schema.SObjectType>{
Expand Down
Loading