@isTest private class InventoryBatchMappingSettingTest { @IsTest static void testMethod1() { Set fromCol = new Set(); Set toCol = new Set(); Inventory_Batch_Mapping__mdt columns = [select From_Columns__c, Inventory_Columns__c from Inventory_Batch_Mapping__mdt where DeveloperName = 'Asset']; Boolean b1 = String.isNotBlank(columns.From_Columns__c); Boolean b2 = String.isNotBlank(columns.Inventory_Columns__c); system.assert(b1 && b2, '保有设备设置From,To的项目为空'); List keyList = columns.From_Columns__c.split(','); List valueList = columns.Inventory_Columns__c.split(','); system.assertEquals(keyList.size(), valueList.size(), '保有设备设置From,To的项目数量不一致'); for (Integer i = 0; i < keyList.size(); i++) { fromCol.add(keyList[i]); toCol.add(valueList[i]); } String queryStr = 'select '+ String.join(new List(fromCol), ', ') + ' from Asset limit 1'; try { Database.query(queryStr); } catch(Exception ex) { system.assert(false, ex); } queryStr = 'select '+ String.join(new List(toCol), ', ') + ' from Inventory_Detail__c limit 1'; try { Database.query(queryStr); } catch(Exception ex) { system.assert(false, ex); } columns = [select From_Columns__c, Inventory_Columns__c from Inventory_Batch_Mapping__mdt where DeveloperName = 'Repair']; b1 = String.isNotBlank(columns.From_Columns__c); b2 = String.isNotBlank(columns.Inventory_Columns__c); system.assert(b1 && b2, '修理设置From,To的项目为空'); keyList = columns.From_Columns__c.split(','); valueList = columns.Inventory_Columns__c.split(','); system.assertEquals(keyList.size(), valueList.size(), '修理设置From,To的项目数量不一致'); fromCol.clear(); toCol.clear(); for (Integer i = 0; i < keyList.size(); i++) { fromCol.add(keyList[i]); toCol.add(valueList[i]); } queryStr = 'select '+ String.join(new List(fromCol), ', ') + ' from Repair__c limit 1'; try { Database.query(queryStr); } catch(Exception ex) { system.assert(false, ex); } queryStr = 'select '+ String.join(new List(toCol), ', ') + ' from Inventory_Detail__c limit 1'; try { Database.query(queryStr); } catch(Exception ex) { system.assert(false, ex); } columns = [select From_Columns__c, Inventory_Columns__c from Inventory_Batch_Mapping__mdt where DeveloperName = 'RAESD']; b1 = String.isNotBlank(columns.From_Columns__c); b2 = String.isNotBlank(columns.Inventory_Columns__c); system.assert(b1 && b2, '借出一览明细设置From,To的项目为空'); keyList = columns.From_Columns__c.split(','); valueList = columns.Inventory_Columns__c.split(','); system.assertEquals(keyList.size(), valueList.size(), '借出一览明细设置From,To的项目数量不一致'); fromCol.clear(); toCol.clear(); for (Integer i = 0; i < keyList.size(); i++) { fromCol.add(keyList[i]); toCol.add(valueList[i]); } queryStr = 'select '+ String.join(new List(fromCol), ', ') + ' from Rental_Apply_Equipment_Set_Detail__c limit 1'; try { Database.query(queryStr); } catch(Exception ex) { system.assert(false, ex); } queryStr = 'select '+ String.join(new List(toCol), ', ') + ' from Inventory_Detail__c limit 1'; try { Database.query(queryStr); } catch(Exception ex) { system.assert(false, ex); } } }