You need to sign in to do that
Don't have an account?

Test Method
I am writing a test class and am having trouble getting a mthod to test correctly. The method looks at a couple of parameters and I am not sure how to pass the parameters to the method through my test class. Can anyone help me?
I need to pass the SelectBox = True and the Participated = false paramerters to this method.
public pageReference saveContacts(){
List<eventRelation> addeventRelation = new List<eventRelation>();
for(cContacts c: getTeamMember()){
IF(c.selectBox == true && c.participated == false){
eventRelation ev = new eventRelation();
ev.RelationId = c.cId;
ev.eventId = eId;
addeventRelation.add(ev);
}
}
insert addeventRelation;
pageRef.setRedirect(true);
return pageRef;
}
My test method.
PageReference page = new PageReference('/apex/EventTeamMemberSelection?scontrolCaching=1&id=' + testEvent.Id);
Test.setCurrentPage(page);
Test.StartTest();
ApexPages.StandardController stdCont = new ApexPages.StandardController(testEvent);
EventTeamMemberSelection extCont = new EventTeamMemberSelection(stdCont);
pageReference addCon = extCont.saveContacts();
pageReference delCon = extCont.deleteContacts();
Test.StopTest();
I need to pass the SelectBox = True and the Participated = false paramerters to this method.
public pageReference saveContacts(){
List<eventRelation> addeventRelation = new List<eventRelation>();
for(cContacts c: getTeamMember()){
IF(c.selectBox == true && c.participated == false){
eventRelation ev = new eventRelation();
ev.RelationId = c.cId;
ev.eventId = eId;
addeventRelation.add(ev);
}
}
insert addeventRelation;
pageRef.setRedirect(true);
return pageRef;
}
My test method.
PageReference page = new PageReference('/apex/EventTeamMemberSelection?scontrolCaching=1&id=' + testEvent.Id);
Test.setCurrentPage(page);
Test.StartTest();
ApexPages.StandardController stdCont = new ApexPages.StandardController(testEvent);
EventTeamMemberSelection extCont = new EventTeamMemberSelection(stdCont);
pageReference addCon = extCont.saveContacts();
pageReference delCon = extCont.deleteContacts();
Test.StopTest();
Always its a best practice to create your test data while writing test methods than relying on (seAllData=True). Here in this Test Class looks like you are getting sContacts from getTeamMember() method, so try creating your sContacts records with SelectBox=True and Participated=False and that should take care of checking your IF condition
Thank you
If (Test.isRunningTest()) {c.selectBox=True;c.participated=True;}
Thank you
Thank you