Add domain method getRecordsContaining (#67)
This commit is contained in:
@@ -793,6 +793,31 @@ public virtual class fflib_SObjects2
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of records where the given field contains the provided value (String.contains)
|
||||
*
|
||||
* @param sObjectField The field to check
|
||||
* @param value The value the field must contain
|
||||
*
|
||||
* @return Returns a list of `SObjects` where the field contains the value
|
||||
*/
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecordsContaining(Schema.SObjectField sObjectField, String value)
|
||||
{
|
||||
List<SObject> result = new List<SObject>();
|
||||
for (SObject record : getRecords())
|
||||
{
|
||||
String fieldValue = (String) record.get(sObjectField);
|
||||
if ((fieldValue == null && value == null)
|
||||
||
|
||||
(fieldValue != null && fieldValue.contains(value))
|
||||
) {
|
||||
result.add(record);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@TestVisible
|
||||
protected virtual List<SObject> getRecordsIsNot(Schema.SObjectField sObjectField, String value)
|
||||
{
|
||||
|
||||
@@ -612,7 +612,7 @@ private class fflib_SObjects2Test
|
||||
{
|
||||
DomainAccounts domain = generateDomain();
|
||||
|
||||
System.Assert.istrue(
|
||||
System.Assert.isTrue(
|
||||
domain.getStringFieldValues(Schema.Account.ShippingCountry)
|
||||
.containsAll(
|
||||
new Set<String>
|
||||
@@ -626,6 +626,16 @@ private class fflib_SObjects2Test
|
||||
);
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldReturnRecordsContainingValue()
|
||||
{
|
||||
DomainAccounts domain = generateDomain();
|
||||
|
||||
List<SObject> records = domain.getRecordsContaining(Schema.Account.ShippingCountry, 'Ire');
|
||||
System.Assert.areEqual(1, records.size());
|
||||
System.Assert.areEqual('B', records.get(0).get('Name'));
|
||||
}
|
||||
|
||||
@IsTest
|
||||
static void itShouldSetFieldValue()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user