You need to sign in to do that
Don't have an account?
Gaurav Sinha 27
Need to do code coverage
HI all
Can anyone help me in writing a test class for below class.
Public Class QuotationController
{
Public quoteInfo Quote {get;set;}
private final Quotation__c QuotationRec;
public QuotationController(ApexPages.StandardController controller) {
QuotationRec=(Quotation__c)controller.getRecord();
Quotation__c QuotationRec=getQuotationRec(QuotationRec.Id);
getQuote(QuotationRec);
}
Public quoteInfo getQuote(Quotation__c Quotation)
{
Query__c Query=[Select Id,Name,Client__c,Destination__c,Duration__c,Hotel_Category__c,Meal_Plan__c,Source__c from Query__c where Id=:Quotation.Query__c];
Quote=New quoteInfo();
Quote.QuoteNumber=Quotation.Name;
Quote.Client=getContactInfo(Query.Client__c);
Quote.QuotationValidTill=Quotation.Quotation_Valid_Till__c;
Quote.companyinfoRec=getcompanyInfo(Quotation.Id);
Quote.hotelInfoList=gethotelInfo(Quotation.Id);
Quote.excursionInfoList=getexcursionInfo(Quotation.Id);
Quote.source=getDestinationInfo(Query.Source__c);
Quote.destination=getDestinationInfo(Query.Destination__c);
Quote.HotelCharge=Quotation.Hotel_Charge__c;
Quote.ExcursionCharge=Quotation.Excursion_Charge__c;
Quote.GST=Quotation.GST__c;
Quote.PackageCost=Quotation.Package_Cost__c;
Quote.Markup=Quotation.Markup__c;
Quote.Itinerary=Quotation.Itinerary__c;
Quote.ProposedByName=Quotation.Createdby.Name;
System.debug('<===Quote==>'+Quote);
return Quote;
}
Public Quotation__c getQuotationRec(String QuotationId)
{
Quotation__c Q=[SELECT Createdby.Name,Excursion_Charge__c,GST__c,Hotel_Charge__c,Id,Itinerary__c,Markup__c,Name,Package_Cost__c,Query__c,Quotation_Valid_Till__c,Quoted_By__c,Status__c FROM Quotation__c Where Id=:QuotationId];
return Q;
}
Public Contact getContactInfo(String ContactId)
{
System.debug('<==ContactId==>'+ContactId);
Contact C=[Select Id,Name,Email,MailingStreet,MailingCity,MailingPostalCode ,MailingCountry,HomePhone From Contact Where Id=:ContactId];
return C;
}
Public Destination__c getDestinationInfo(String DestinationId)
{
Destination__c D=[Select Id,Name,Country__c From Destination__c Where Id=:DestinationId];
return D;
}
Public companyInfo getcompanyInfo(String QuoteId)
{
Company_Information__c CompInf=Company_Information__c.getInstance(UserInfo.getOrganizationId());
companyInfo CI=New companyInfo();
CI.Name=CompInf.Name;
CI.Address=CompInf.Address__c;
CI.Email=CompInf.Email__c;
CI.Phone=CompInf.Mobile__c;
CI.Website=CompInf.Website__c;
CI.Follow=CompInf.Follow_on_Facebook__c;
return CI;
}
Public List<hotelInfo> gethotelInfo(String QuoteId)
{
List<hotelInfo>hotelInfoList=New List<hotelInfo>();
List<Hotel__c>HotelList=New List<Hotel__c>();
Map<Id,Hotel_Information__c>HotelInfoMap=New Map<Id,Hotel_Information__c>();
Set<Id>HotelIds=New Set<Id>();
List<Hotel_Information__c>HIlist=[Select ID,Hotel__c,Hotel_Charge__c,Request__c,Payable_Amount__c from Hotel_Information__c where Quotation__c=:QuoteId];
for(Hotel_Information__c E:HIlist )
{
HotelInfoMap.put(E.Hotel__c,E);
HotelIds.add(E.Hotel__c);
}
HotelList=[Select Id,Name,Rate__c,Category__c,City__c,Country__c,State__c from Hotel__c where id=:HotelIds];
for(Hotel__c E:HotelList)
{
Hotel_Information__c HIN=HotelInfoMap.get(E.Id);
hotelInfo HI=New hotelInfo();
HI.Name=E.Name;
HI.Category=E.Category__c;
HI.City=E.City__c;
HI.Country=E.Country__c;
HI.Rate=E.Rate__c;
HI.NumberofNights=HIN.Request__c;
HI.Amount=HIN.Payable_Amount__c;
hotelInfoList.add(HI);
}
return hotelInfoList;
}
Public List<excursionInfo> getexcursionInfo(String QuoteId)
{
List<excursionInfo>excursionInfoList=New List<excursionInfo>();
List<Excursions__c>ExcursionsList=New List<Excursions__c>();
Map<Id,Excursion_INformation__c>ExcursionMap=New Map<Id,Excursion_INformation__c>();
Set<Id>ExcursionIds=New Set<Id>();
List<Excursion_INformation__c>EIlist=[Select ID,Excursion__c,Excursion_Charge__c,Number_of_Persons__c,Payable_Amount__c from Excursion_INformation__c where Quotation__c=:QuoteId];
for(Excursion_INformation__c E:EIlist )
{
ExcursionMap.put(E.Excursion__c,E);
ExcursionIds.add(E.Excursion__c);
}
ExcursionsList=[Select Id,Name,Rate__c from Excursions__c where id=:ExcursionIds];
for(Excursions__c E:ExcursionsList)
{
Excursion_INformation__c EIN=ExcursionMap.get(E.Id);
excursionInfo EI=New excursionInfo();
EI.Name=E.Name;
EI.Rate=E.Rate__c;
EI.NumberofPerson=EIN.Number_of_Persons__c;
EI.Amount=EIN.Payable_Amount__c;
excursionInfoList.add(EI);
}
return excursionInfoList;
}
Public class quoteInfo
{
public string QuoteNumber {get;set;}
public contact Client {get;set;}
public Date QuotationValidTill {get;set;}
public companyInfo companyinfoRec {get;set;}
public list<hotelInfo> hotelInfoList {get;set;}
public list<excursionInfo> excursionInfoList {get;set;}
public Destination__c source {get;set;}
public Destination__c destination {get;set;}
public Decimal HotelCharge {get;set;}
public Decimal ExcursionCharge {get;set;}
public Decimal GST {get;set;}
public Decimal PackageCost {get;set;}
public Decimal Markup {get;set;}
public string Itinerary {get;set;}
public string ProposedByName {get;set;}
}
Public class companyInfo
{
public string Name {get;set;}
public string Address {get;set;}
public string Email {get;set;}
public string Phone {get;set;}
public string Website {get;set;}
public string Follow{get;set;}
}
Public class hotelInfo
{
public string Name {get;set;}
public string Category {get;set;}
public string City {get;set;}
public string Country {get;set;}
public Decimal Rate {get;set;}
public Decimal NumberofNights {get;set;}
public Decimal Amount {get;set;}
}
Public class excursionInfo
{
public string Name {get;set;}
public Decimal Rate {get;set;}
public Decimal NumberofPerson {get;set;}
public Decimal Amount {get;set;}
}
}
Can anyone help me in writing a test class for below class.
Public Class QuotationController
{
Public quoteInfo Quote {get;set;}
private final Quotation__c QuotationRec;
public QuotationController(ApexPages.StandardController controller) {
QuotationRec=(Quotation__c)controller.getRecord();
Quotation__c QuotationRec=getQuotationRec(QuotationRec.Id);
getQuote(QuotationRec);
}
Public quoteInfo getQuote(Quotation__c Quotation)
{
Query__c Query=[Select Id,Name,Client__c,Destination__c,Duration__c,Hotel_Category__c,Meal_Plan__c,Source__c from Query__c where Id=:Quotation.Query__c];
Quote=New quoteInfo();
Quote.QuoteNumber=Quotation.Name;
Quote.Client=getContactInfo(Query.Client__c);
Quote.QuotationValidTill=Quotation.Quotation_Valid_Till__c;
Quote.companyinfoRec=getcompanyInfo(Quotation.Id);
Quote.hotelInfoList=gethotelInfo(Quotation.Id);
Quote.excursionInfoList=getexcursionInfo(Quotation.Id);
Quote.source=getDestinationInfo(Query.Source__c);
Quote.destination=getDestinationInfo(Query.Destination__c);
Quote.HotelCharge=Quotation.Hotel_Charge__c;
Quote.ExcursionCharge=Quotation.Excursion_Charge__c;
Quote.GST=Quotation.GST__c;
Quote.PackageCost=Quotation.Package_Cost__c;
Quote.Markup=Quotation.Markup__c;
Quote.Itinerary=Quotation.Itinerary__c;
Quote.ProposedByName=Quotation.Createdby.Name;
System.debug('<===Quote==>'+Quote);
return Quote;
}
Public Quotation__c getQuotationRec(String QuotationId)
{
Quotation__c Q=[SELECT Createdby.Name,Excursion_Charge__c,GST__c,Hotel_Charge__c,Id,Itinerary__c,Markup__c,Name,Package_Cost__c,Query__c,Quotation_Valid_Till__c,Quoted_By__c,Status__c FROM Quotation__c Where Id=:QuotationId];
return Q;
}
Public Contact getContactInfo(String ContactId)
{
System.debug('<==ContactId==>'+ContactId);
Contact C=[Select Id,Name,Email,MailingStreet,MailingCity,MailingPostalCode ,MailingCountry,HomePhone From Contact Where Id=:ContactId];
return C;
}
Public Destination__c getDestinationInfo(String DestinationId)
{
Destination__c D=[Select Id,Name,Country__c From Destination__c Where Id=:DestinationId];
return D;
}
Public companyInfo getcompanyInfo(String QuoteId)
{
Company_Information__c CompInf=Company_Information__c.getInstance(UserInfo.getOrganizationId());
companyInfo CI=New companyInfo();
CI.Name=CompInf.Name;
CI.Address=CompInf.Address__c;
CI.Email=CompInf.Email__c;
CI.Phone=CompInf.Mobile__c;
CI.Website=CompInf.Website__c;
CI.Follow=CompInf.Follow_on_Facebook__c;
return CI;
}
Public List<hotelInfo> gethotelInfo(String QuoteId)
{
List<hotelInfo>hotelInfoList=New List<hotelInfo>();
List<Hotel__c>HotelList=New List<Hotel__c>();
Map<Id,Hotel_Information__c>HotelInfoMap=New Map<Id,Hotel_Information__c>();
Set<Id>HotelIds=New Set<Id>();
List<Hotel_Information__c>HIlist=[Select ID,Hotel__c,Hotel_Charge__c,Request__c,Payable_Amount__c from Hotel_Information__c where Quotation__c=:QuoteId];
for(Hotel_Information__c E:HIlist )
{
HotelInfoMap.put(E.Hotel__c,E);
HotelIds.add(E.Hotel__c);
}
HotelList=[Select Id,Name,Rate__c,Category__c,City__c,Country__c,State__c from Hotel__c where id=:HotelIds];
for(Hotel__c E:HotelList)
{
Hotel_Information__c HIN=HotelInfoMap.get(E.Id);
hotelInfo HI=New hotelInfo();
HI.Name=E.Name;
HI.Category=E.Category__c;
HI.City=E.City__c;
HI.Country=E.Country__c;
HI.Rate=E.Rate__c;
HI.NumberofNights=HIN.Request__c;
HI.Amount=HIN.Payable_Amount__c;
hotelInfoList.add(HI);
}
return hotelInfoList;
}
Public List<excursionInfo> getexcursionInfo(String QuoteId)
{
List<excursionInfo>excursionInfoList=New List<excursionInfo>();
List<Excursions__c>ExcursionsList=New List<Excursions__c>();
Map<Id,Excursion_INformation__c>ExcursionMap=New Map<Id,Excursion_INformation__c>();
Set<Id>ExcursionIds=New Set<Id>();
List<Excursion_INformation__c>EIlist=[Select ID,Excursion__c,Excursion_Charge__c,Number_of_Persons__c,Payable_Amount__c from Excursion_INformation__c where Quotation__c=:QuoteId];
for(Excursion_INformation__c E:EIlist )
{
ExcursionMap.put(E.Excursion__c,E);
ExcursionIds.add(E.Excursion__c);
}
ExcursionsList=[Select Id,Name,Rate__c from Excursions__c where id=:ExcursionIds];
for(Excursions__c E:ExcursionsList)
{
Excursion_INformation__c EIN=ExcursionMap.get(E.Id);
excursionInfo EI=New excursionInfo();
EI.Name=E.Name;
EI.Rate=E.Rate__c;
EI.NumberofPerson=EIN.Number_of_Persons__c;
EI.Amount=EIN.Payable_Amount__c;
excursionInfoList.add(EI);
}
return excursionInfoList;
}
Public class quoteInfo
{
public string QuoteNumber {get;set;}
public contact Client {get;set;}
public Date QuotationValidTill {get;set;}
public companyInfo companyinfoRec {get;set;}
public list<hotelInfo> hotelInfoList {get;set;}
public list<excursionInfo> excursionInfoList {get;set;}
public Destination__c source {get;set;}
public Destination__c destination {get;set;}
public Decimal HotelCharge {get;set;}
public Decimal ExcursionCharge {get;set;}
public Decimal GST {get;set;}
public Decimal PackageCost {get;set;}
public Decimal Markup {get;set;}
public string Itinerary {get;set;}
public string ProposedByName {get;set;}
}
Public class companyInfo
{
public string Name {get;set;}
public string Address {get;set;}
public string Email {get;set;}
public string Phone {get;set;}
public string Website {get;set;}
public string Follow{get;set;}
}
Public class hotelInfo
{
public string Name {get;set;}
public string Category {get;set;}
public string City {get;set;}
public string Country {get;set;}
public Decimal Rate {get;set;}
public Decimal NumberofNights {get;set;}
public Decimal Amount {get;set;}
}
Public class excursionInfo
{
public string Name {get;set;}
public Decimal Rate {get;set;}
public Decimal NumberofPerson {get;set;}
public Decimal Amount {get;set;}
}
}