• kristhoper sayson
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
How can i assert for the return value of save(), Here is my code for class
public pagereference save() {

        ipAsset.AsLi_Status__c = AsLi_Constants.ASSETSTATUS_DRAFT;
        try {
            copyAccountCompanyDesc();
            upsert ipAsset;

            for(AsLi_AssetTechnology__c at : assetTechTags){
                if(at.AsLi_AssetMD__c == null){
                    at.AsLi_AssetMD__c = ipAsset.Id;
                }
            }

            upsert assetTechTags;
            
            
            PageReference IPAssetPage = new ApexPages.StandardController(ipasset).view();
                
            IPAssetPage.setRedirect(true);
            return IPAssetPage;
            
        } catch (DmlException ex) {
            ApexPages.addMessages(ex);
            return null;
        }
            
    }
Here is my test class
RecordType rt = [select id,Name from RecordType where SobjectType='AsLi_IPAsset__c' And Name = 'RFP Answer'];
        System.debug(rt);
        
        List<AsLi_TechnologiesTags__c> techTest = new List<AsLi_TechnologiesTags__c>();
        AsLi_TechnologiesTags__c tags1 = new AsLi_TechnologiesTags__c(Name = 'Google', AsLi_Active__c = True, AsLi_ForApproval__c = False);
        AsLi_TechnologiesTags__c tags2 = new AsLi_TechnologiesTags__c(Name = 'Google Talk', AsLi_Active__c = True, AsLi_ForApproval__c = False);
        AsLi_TechnologiesTags__c tags3 = new AsLi_TechnologiesTags__c(Name = 'Google Drive', AsLi_Active__c = True, AsLi_ForApproval__c = False);
        
        techTest.add(tags1);
        techTest.add(tags2);
        techTest.add(tags3);
        
        insert techTest;
        
        AsLi_IPAsset__c asset2 = new AsLi_IPAsset__c(RecordTypeId = rt.Id, Name = 'test2');
        insert asset2;
        PageReference pageRef = new PageReference('https://c.cs24.visual.force.com/apex/AsLi_AssetEdit/?Id=' + asset2.Id);



Test.setCurrentPage(pageRef);
        
        ApexPages.StandardController sCon = new ApexPages.StandardController(asset2);
        AsLi_AssetEditControllerExtension controller = new  AsLi_AssetEditControllerExtension(sCon);
        AsLi_AssetEditControllerExtension.TechnologyWrapper wr = new AsLi_AssetEditControllerExtension.TechnologyWrapper();
        controller.showPopup();
        Test.startTest();
        PageReference search1 = controller.showPopup();
        controller.searchText = 'Google';
        controller.search();
        controller.getOnFirstPage();
        controller.getOnLastPage();
        controller.add();   
        controller.save();
        Test.stopTest();
        
        
        
        System.assertEquals(3,controller.searchCount.size());
        AsLi_AssetTechnology__c assetTag = [Select Id, Name, AsLi_TechnologiesTagsMD__c, AsLi_AssetMD__c From AsLi_AssetTechnology__c];
        
        System.debug(assetTag);
        System.assertEquals(asset2.id,assetTag.AsLi_AssetMD__c);
        System.assertEquals(techTest[0].id,assetTag.AsLi_TechnologiesTagsMD__c);
        

        
    }
Im working on testting my class and i want to assert this 2 method
how can i assert the pagereference. Here is my code:
public PageReference backToSearchResult(){
        PageReference pageRef = new PageReference('/apex/AsLi_AssetSearch');
        return pageRef;
    }
    
    public PageReference updateViewCount() {
        ipAsset.AsLi_Asset_View_Count__c = ipAsset.AsLi_Asset_View_Count__c + 1;
        update ipAsset;
        
        return null;
    }

Thanks
Mark


 
How can i assert for the return value of save(), Here is my code for class
public pagereference save() {

        ipAsset.AsLi_Status__c = AsLi_Constants.ASSETSTATUS_DRAFT;
        try {
            copyAccountCompanyDesc();
            upsert ipAsset;

            for(AsLi_AssetTechnology__c at : assetTechTags){
                if(at.AsLi_AssetMD__c == null){
                    at.AsLi_AssetMD__c = ipAsset.Id;
                }
            }

            upsert assetTechTags;
            
            
            PageReference IPAssetPage = new ApexPages.StandardController(ipasset).view();
                
            IPAssetPage.setRedirect(true);
            return IPAssetPage;
            
        } catch (DmlException ex) {
            ApexPages.addMessages(ex);
            return null;
        }
            
    }
Here is my test class
RecordType rt = [select id,Name from RecordType where SobjectType='AsLi_IPAsset__c' And Name = 'RFP Answer'];
        System.debug(rt);
        
        List<AsLi_TechnologiesTags__c> techTest = new List<AsLi_TechnologiesTags__c>();
        AsLi_TechnologiesTags__c tags1 = new AsLi_TechnologiesTags__c(Name = 'Google', AsLi_Active__c = True, AsLi_ForApproval__c = False);
        AsLi_TechnologiesTags__c tags2 = new AsLi_TechnologiesTags__c(Name = 'Google Talk', AsLi_Active__c = True, AsLi_ForApproval__c = False);
        AsLi_TechnologiesTags__c tags3 = new AsLi_TechnologiesTags__c(Name = 'Google Drive', AsLi_Active__c = True, AsLi_ForApproval__c = False);
        
        techTest.add(tags1);
        techTest.add(tags2);
        techTest.add(tags3);
        
        insert techTest;
        
        AsLi_IPAsset__c asset2 = new AsLi_IPAsset__c(RecordTypeId = rt.Id, Name = 'test2');
        insert asset2;
        PageReference pageRef = new PageReference('https://c.cs24.visual.force.com/apex/AsLi_AssetEdit/?Id=' + asset2.Id);



Test.setCurrentPage(pageRef);
        
        ApexPages.StandardController sCon = new ApexPages.StandardController(asset2);
        AsLi_AssetEditControllerExtension controller = new  AsLi_AssetEditControllerExtension(sCon);
        AsLi_AssetEditControllerExtension.TechnologyWrapper wr = new AsLi_AssetEditControllerExtension.TechnologyWrapper();
        controller.showPopup();
        Test.startTest();
        PageReference search1 = controller.showPopup();
        controller.searchText = 'Google';
        controller.search();
        controller.getOnFirstPage();
        controller.getOnLastPage();
        controller.add();   
        controller.save();
        Test.stopTest();
        
        
        
        System.assertEquals(3,controller.searchCount.size());
        AsLi_AssetTechnology__c assetTag = [Select Id, Name, AsLi_TechnologiesTagsMD__c, AsLi_AssetMD__c From AsLi_AssetTechnology__c];
        
        System.debug(assetTag);
        System.assertEquals(asset2.id,assetTag.AsLi_AssetMD__c);
        System.assertEquals(techTest[0].id,assetTag.AsLi_TechnologiesTagsMD__c);
        

        
    }
Im working on testting my class and i want to assert this 2 method
how can i assert the pagereference. Here is my code:
public PageReference backToSearchResult(){
        PageReference pageRef = new PageReference('/apex/AsLi_AssetSearch');
        return pageRef;
    }
    
    public PageReference updateViewCount() {
        ipAsset.AsLi_Asset_View_Count__c = ipAsset.AsLi_Asset_View_Count__c + 1;
        update ipAsset;
        
        return null;
    }

Thanks
Mark