-
Notifications
You must be signed in to change notification settings - Fork 518
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
bugfix for Issue 221 #449
Open
jprichter
wants to merge
14
commits into
apex-enterprise-patterns:master
Choose a base branch
from
jprichter:bugfix/issue-221
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
bugfix for Issue 221 #449
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5bc74ad
fix from @dsurfleet
jprichter b9288bd
unit test for registerDirty with relationship to new sObject
jprichter 8c59274
fix: add unit test to cover update bug
ClayChipps 32a23f4
fix: remove all changes
ClayChipps 937d444
fix: add additional resolve logic
ClayChipps c72db7b
Merge branch 'master' into bugfix/issue-221
ClayChipps c06bde8
fix: remove null check
ClayChipps 2e95e52
fix: remove resolved relationships
ClayChipps 032777b
fix: revert to use previous IDML
ClayChipps 8e8af54
Merge branch 'master' into bugfix/issue-221
ClayChipps fb866b2
fix: prevent null pointer on dmlInsert test
ClayChipps 6ab9b1c
Merge branch 'master' into bugfix/issue-221
ClayChipps 6dcecda
Merge branch 'master' into bugfix/issue-221
ImJohnMDaniel f6d4f7a
Merge branch 'master' into bugfix/issue-221
ImJohnMDaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,6 +608,63 @@ private with sharing class fflib_SObjectUnitOfWorkTest | |
); | ||
} | ||
|
||
@IsTest | ||
private static void testRegisterDirtyWithRelationship() { | ||
// GIVEN an existing opportunity | ||
Opportunity existingOpp = new Opportunity( | ||
Id = fflib_IDGenerator.generate(Schema.Opportunity.SObjectType), | ||
Name = 'Existing Opportunity', | ||
StageName = 'Closed', | ||
CloseDate = System.today() | ||
); | ||
// AND an existing Account to which the existing opportunity will be related to | ||
Account newAccount = new Account( | ||
Name = 'New Account' | ||
); | ||
|
||
// WHEN | ||
Test.startTest(); | ||
MockDMLWithInsertIds mockDML = new MockDMLWithInsertIds(); | ||
List<Schema.SObjectType> mySobjects = new List<Schema.SObjectType>{ | ||
Opportunity.SObjectType, | ||
Account.SObjectType | ||
}; | ||
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(mySobjects, mockDML); | ||
uow.registerNew(newAccount); | ||
uow.registerDirty(existingOpp, Opportunity.AccountId, newAccount); | ||
uow.commitWork(); | ||
Test.stopTest(); | ||
|
||
// THEN | ||
System.Assert.isTrue( | ||
new fflib_MatcherDefinitions.SObjectsWith( | ||
new List<Map<SObjectField, Object>>{ | ||
new Map<SObjectField, Object> | ||
{ | ||
Account.Id => newAccount.Id, | ||
Account.Name => 'New Account' | ||
} | ||
} | ||
).matches(mockDML.recordsForInsert), | ||
'The new account record does not match' | ||
); | ||
|
||
// AND | ||
System.Assert.isTrue( | ||
new fflib_MatcherDefinitions.SObjectsWith( | ||
new List<Map<SObjectField, Object>>{ | ||
new Map<SObjectField, Object> | ||
{ | ||
Opportunity.Id => existingOpp.Id, | ||
Opportunity.Name => 'Existing Opportunity', | ||
Opportunity.StageName => 'Closed', | ||
Opportunity.AccountId => newAccount.Id | ||
} | ||
} | ||
).matches(mockDML.recordsForUpdate), | ||
'The opportunity record should be related to the new Account' | ||
); | ||
} | ||
@IsTest | ||
private static void testRegisterUpsert() { | ||
Opportunity existingOpp = new Opportunity( | ||
|
@@ -848,6 +905,43 @@ private with sharing class fflib_SObjectUnitOfWorkTest | |
} | ||
} | ||
|
||
private class MockDMLWithInsertIds implements fflib_SObjectUnitOfWork.IDML | ||
{ | ||
public List<SObject> recordsForInsert = new List<SObject>(); | ||
public List<SObject> recordsForUpdate = new List<SObject>(); | ||
public List<SObject> recordsForDelete = new List<SObject>(); | ||
public List<SObject> recordsForRecycleBin = new List<SObject>(); | ||
public List<SObject> recordsForEventPublish = new List<SObject>(); | ||
|
||
public void dmlInsert(List<SObject> objList) | ||
{ | ||
for (SObject obj : objList) { | ||
obj.Id = fflib_IDGenerator.generate(obj.getSObjectType()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ClayChipps and @jprichter -- Please add a null check on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
this.recordsForInsert.addAll(objList); | ||
} | ||
|
||
public void dmlUpdate(List<SObject> objList) | ||
{ | ||
this.recordsForUpdate.addAll(objList); | ||
} | ||
|
||
public void dmlDelete(List<SObject> objList) | ||
{ | ||
this.recordsForDelete.addAll(objList); | ||
} | ||
|
||
public void eventPublish(List<SObject> objList) | ||
{ | ||
this.recordsForEventPublish.addAll(objList); | ||
} | ||
|
||
public void emptyRecycleBin(List<SObject> objList) | ||
{ | ||
this.recordsForRecycleBin.addAll(objList); | ||
} | ||
} | ||
|
||
public class DerivedUnitOfWorkException extends Exception {} | ||
public class FailDoingWorkException extends Exception {} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ClayChipps and @jprichter -- Any reason why you did not just simply modify the existing
MockDML
??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use the existing MockDML.