So here's my issue. I wrote a Trigger in order to handle CaseShares, and the problem that I am having is at.
for(Case cs : trigger.new){
if(PartnerUsermap.containsKey(cs.CreatedById)){
for(GroupMember grpmem : GroupMemberList){
//Here! if(grpmem.UserOrGroupId == cs.CreatedById){ --Group member is a Portal user, and this checks if he created the Case
CaseShare csshare = new CaseShare (CaseId = cs.id,UserOrGroupId = grpmem.GroupId,CaseAccessLevel = 'Edit'); //This line doesn't get coverage, I'm assuming because I'm not getting a match
CsShareList.add(csshare);
The problem is that I can't get a good comparission when developing my test class, and not I'm sure how to feed in my data from my test class in order to properly get the match. Below is my test class. I think I'm close to getting it with my System.runas, but I'm stuck.. Any guidance would be great
static testMethod void myUnitTest1() {
List < Case > leadList = new List < Case > ();
List < CaseShare > leadShareList = new list < CaseShare > ();
String dateString = String.valueof(Datetime.now()).replace(' ', '').replace(':', '').replace('-', '');
String orgId = UserInfo.getOrganizationId();
Integer randomInt = Integer.valueOf(math.rint(math.random() * 1000000));
String uniqueName = orgId + dateString + randomInt;
Account accInd = new account(name = 'individual');
insert accInd;
Contact contact = new Contact(LastName = 'hello', FirstName = 'World', Email = '[email protected]', AccountId = accInd.Id);
insert contact;
Profile p = [SELECT Id FROM Profile WHERE UserType = 'PowerPartner' limit 1 ];
User u = new User(Alias = 'standt',
Email = '[email protected]',
EmailEncodingKey = 'UTF-8',
LastName = 'Testing',
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US',
ProfileId = p.Id,
TimeZoneSidKey = 'America/Los_Angeles',
Username = uniqueName + '@test' + orgId + '.org',
ContactId = contact.id);
Product2 p2 = new Product2();
p2.Name = 'TestProduct';
p2.IsActive = True;
p2.AE_Text__c = 'TestText';
p2.Item_number__c = 'TestNumber';
insert p2;
Case c = new Case();
c.Product_old__c = p2.id;
c.Status = 'New';
c.Origin = 'Email';
c.Case_Level__c = 'Level 1 - Product Concept/Selection';
c.Territory__c = 'Asia';
c.Region__c = 'CHINA';
system.debug('Creating a New case! ' + c + 'Created by! ' + c.CreatedById);
System.runAs(u) {
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId());
insert c;
GroupMember groupMemberStore = [select GroupId, UserOrGroupId from GroupMember limit 1];
system.debug('GroupMemberStore ' + groupMemberStore);
CaseShare cs = new CaseShare();
cs.CaseId = c.id;
cs.UserOrGroupId = groupMemberStore.UserOrGroupId;
cs.CaseAccessLevel = 'Edit';
system.debug('ls ++!@+! ' + cs);
insert cs;
}
Case newCase = [SELECT Id, CaseNumber, CreatedById FROM Case WHERE CreatedById = : u.id]; //Can't figure this out
System.debug('NEW CASE ' + newCase);
System.assertEquals(u.Id, newCase.CreatedById);
}