Support for mocking multiple times #136
santiagoparradev
started this conversation in
Ideas
Replies: 2 comments 3 replies
-
|
Hi @santiagoparradev , As far as I understand, you would like a "stack" from which the mocked result will be retrieved. e.g. Account accountA = new Account(Name = 'Test A');
SOQL.mock('AccountQuery', accountA);
Account accountB = new Account(Name = 'Test B');
SOQL.mock('AccountQuery', accountB);
Test.startTest();
Account account1 = SOQL.of(Account.SObjectType).mockId('AccountQuery').toObject();
Account account2 = SOQL.of(Account.SObjectType).mockId('AccountQuery').toObject();
Test.stopTest();
Assert.areEqual(accountA, account1);
Assert.areEqual(accountB, account2);If Is that correct? |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Hi @santiagoparradev , It has been a long time, but I finally started working on the mocking stack. // Setup
SOQL.mock('mockingQuery').thenReturn(new Account(Name = 'Test 1'));
SOQL.mock('mockingQuery').thenReturn(new Account(Name = 'Test 2'));
SOQL.mock('mockingQuery').thenReturn(new Account(Name = 'Test 3'));
// Test
SOQL.Queryable query = SOQL.of(Account.SObjectType).with(Account.Name).mockId('mockingQuery');
Account acc1 = (Account) query.toObject();
Account acc2 = (Account) query.toObject();
Account acc3 = (Account) query.toObject();
Account acc4 = (Account) query.toObject();
// Verify
Assert.areEqual('Test 1', acc1.Name, 'The returned account name should match the expected one.');
Assert.areEqual('Test 2', acc2.Name, 'The returned account name should match the expected one.');
Assert.areEqual('Test 3', acc3.Name, 'The returned account name should match the expected one.');
Assert.areEqual('Test 3', acc4.Name, 'The returned account name should match the expected one.'); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
sometimes the same query can run múltiple times throughout a process
it would be great to be able to
SOQL.mockOnce(mockId, firstCall);
SOQL.mockOnce(mockId, secondCall);
Beta Was this translation helpful? Give feedback.
All reactions