@isTest private class AgencyCampaignControllerTest { static Account keiyaku1; static Account keiyaku2; static Account keiyaku3; static Account keiyaku4; static Account sellerA; static Product2__c pro1; static Product2__c pro2; static Product2__c pro3; static final String RC_HANBAOITEN = '販売店'; static final String RC_KEIYAKU = '契約'; static void initAcData() { Product2 prod01 = new Product2(Name='Test01'); prod01.ProductCode='Test01'; prod01.Asset_Model_No__c = 'Test01'; prod01.SFDA_Status__c = '有効'; prod01.Dealer_special_Object__c = true; prod01.Family = 'GI'; prod01.Category2__c = '耗材'; prod01.Category3__c = '其他'; prod01.Category4__c = '其他'; prod01.Category5__c = '其他'; Product2 prod02 = new Product2(Name='Test02'); prod02.ProductCode='Test02'; prod02.Asset_Model_No__c = 'Test02'; prod02.SFDA_Status__c = '有効'; prod02.Dealer_special_Object__c = true; prod02.Family = 'GI'; prod02.Category2__c = '本体'; prod02.Category3__c = '其他'; prod02.Category4__c = '其他'; prod02.Category5__c = '其他'; Product2 prod03 = new Product2(Name='Test03'); prod03.ProductCode='Test03'; prod03.Asset_Model_No__c = 'Test03'; prod03.SFDA_Status__c = '有効'; prod03.Dealer_special_Object__c = true; prod03.Family = 'SP'; prod03.Category2__c = '附属品'; prod03.Category3__c = '其他'; prod03.Category4__c = '其他'; prod03.Category5__c = '其他'; insert new Product2[]{prod01,prod02,prod03}; pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id); pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id); pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id); insert new Product2__c[] {pro1, pro2,pro3}; //販売店 RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1]; sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Delete_Flag__c = false; sellerA.Contract_Department_Class__c = 'ET'; sellerA.Contract_Decide_Start_Date__c= Date.today(); sellerA.Contract_Decide_End_Date__c= Date.today().addDays(1); insert sellerA; //契約 RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1]; keiyaku1 = new Account(Name = '*'); keiyaku1.RecordTypeId = recKeiyaku.id; keiyaku1.Agent_Ref__c = sellerA.id; keiyaku1.ParentId = sellerA.id; keiyaku1.Delete_Flag__c = false; keiyaku1.Contract_Department_Class__c = 'ET'; keiyaku1.Contract_Decide_Start_Date__c = Date.today().addDays(-1); keiyaku1.Contract_Decide_End_Date__c = Date.today().addDays(1); insert keiyaku1; keiyaku2 = new Account(Name = '*'); keiyaku2.RecordTypeId = recKeiyaku.id; keiyaku2.Agent_Ref__c = sellerA.id; keiyaku2.ParentId = sellerA.id; keiyaku2.Delete_Flag__c = false; keiyaku2.Contract_Department_Class__c = 'ET'; keiyaku2.Contract_Decide_Start_Date__c = Date.today().addDays(-1); keiyaku2.Contract_Decide_End_Date__c = Date.today().addDays(1); insert keiyaku2; keiyaku3 = new Account(Name = '*'); keiyaku3.RecordTypeId = recKeiyaku.id; keiyaku3.Agent_Ref__c = sellerA.id; keiyaku3.ParentId = sellerA.id; keiyaku3.Delete_Flag__c = false; keiyaku3.Contract_Department_Class__c = 'ET'; keiyaku3.Contract_Decide_Start_Date__c = Date.today().addDays(-1); keiyaku3.Contract_Decide_End_Date__c = Date.today().addDays(1); insert keiyaku3; keiyaku4 = new Account(Name = '*'); keiyaku4.RecordTypeId = recKeiyaku.id; keiyaku4.Agent_Ref__c = sellerA.id; keiyaku4.ParentId = sellerA.id; keiyaku4.Delete_Flag__c = false; keiyaku4.Contract_Department_Class__c = 'ET'; keiyaku4.Contract_Decide_Start_Date__c = Date.today().addDays(-1); keiyaku4.Contract_Decide_End_Date__c = Date.today().addDays(1); insert keiyaku4; //keiyaku = [select Id from Account where Id = :keiyaku.Id]; } @isTest static void init_test() { initAcData(); PageReference page = new PageReference('/apex/AgencyCampaign'); System.Test.setCurrentPage(page); AgencyCampaignController conTest = new AgencyCampaignController(); conTest.init(); System.assertEquals(3, conTest.productInfoListview.size()); conTest.keyword = 'Test01'; conTest.searchHospital(); System.assertEquals(1, conTest.productInfoListview.size()); conTest.category1 = 'GI'; conTest.category2 = '耗材'; conTest.category3 = '其他'; conTest.category4 = '其他'; conTest.category5 = '其他'; conTest.searchHospital(); System.assertEquals(1, conTest.productInfoListview.size()); conTest.dpc.Agent_Ref__c = null; conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null; conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); Account acc = [select Id from Account limit 1]; conTest.dpc.Agent_Ref__c = acc.id; conTest.accContact=null; conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null; conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); conTest.keyword = 'Test01'; conTest.searchHospital(); conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].pro.Id = null; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1); conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); conTest.dpc.Agent_Ref__c = sellerA.id; //conTest.showParentManagementCode(); conTest.refreshPageSize(); //System.assertEquals(1, dPList.size()); } @isTest static void selectfill() { initAcData(); //促销 Consumable_Promotion__c cpn = new Consumable_Promotion__c(); cpn.CurrencyIsoCode = 'CNY'; insert cpn; Dealer_Product__c dp1 = new Dealer_Product__c(); dp1.Dealer_Product2__c = pro1.Id; dp1.Dealer_Contact__c = keiyaku1.Id; dp1.Special_Discount__c =60; dp1.Special_Campaign_Price__c = 200; dp1.Campaign_StartDate__c = Date.today().addDays(-1); dp1.Campaign_EndDate__c = Date.today().addDays(1); dp1.Promotion_No__c = cpn.id; Dealer_Product__c dp2 = new Dealer_Product__c(); dp2.Dealer_Product2__c = pro2.Id; dp2.Dealer_Contact__c = keiyaku2.Id; dp2.Special_Campaign_Price__c = 200; dp2.Campaign_StartDate__c = Date.today().addDays(-1); dp2.Campaign_EndDate__c = Date.today().addDays(1); dp2.Promotion_No__c = cpn.id; Dealer_Product__c dp3 = new Dealer_Product__c(); dp3.Dealer_Product2__c = pro3.Id; dp3.Dealer_Contact__c = keiyaku3.Id; dp3.Special_Campaign_Price__c = 200; dp3.Campaign_StartDate__c = Date.today().addDays(-1); dp3.Campaign_EndDate__c = Date.today().addDays(1); dp3.Promotion_No__c = cpn.id; Dealer_Product__c dp4 = new Dealer_Product__c(); dp4.Dealer_Product2__c = pro3.Id; dp4.Dealer_Contact__c = keiyaku1.Id; dp4.Special_Campaign_Price__c = 200; dp4.Campaign_StartDate__c = Date.today().addDays(1); dp4.Campaign_EndDate__c = Date.today().addDays(-1); dp4.Promotion_No__c = cpn.id; dp4 = new Dealer_Product__c(); dp4.Dealer_Product2__c = pro2.Id; dp4.Dealer_Contact__c = keiyaku2.Id; dp4.Special_Campaign_Price__c = 200; dp4.Campaign_StartDate__c = Date.today().addDays(1); dp4.Campaign_EndDate__c = null; dp4.Promotion_No__c = cpn.id; insert new Dealer_Product__c[] {dp1, dp2,dp3,dp4}; PageReference page = new PageReference('/apex/AgencyCampaign?id='+cpn.id); System.Test.setCurrentPage(page); AgencyCampaignController conTest = new AgencyCampaignController(); conTest.init(); System.assertEquals(5, conTest.lineInfoList.size()); conTest.lineNo = 2; conTest.pagesize = 2; System.assertEquals(3, conTest.productInfoListview.size()); conTest.keyword = 'Test01'; conTest.searchHospital(); //System.assertEquals(1, conTest.productInfoListview.size()); conTest.category1 = 'GI'; conTest.category2 = '耗材'; conTest.category3 = '其他'; conTest.category4 = '其他'; conTest.category5 = '其他'; conTest.showcategory2(); conTest.searchHospital(); System.assertEquals(1, conTest.productInfoListview.size()); conTest.showcategory3(); conTest.searchHospital(); System.assertEquals(1, conTest.productInfoListview.size()); conTest.showcategory4(); conTest.searchHospital(); System.assertEquals(1, conTest.productInfoListview.size()); conTest.showcategory5(); conTest.searchHospital(); System.assertEquals(1, conTest.productInfoListview.size()); conTest.category1 = ''; conTest.category2 = ''; conTest.category3 = ''; conTest.category4 = ''; conTest.category5 = ''; conTest.keyword = 'Test'; conTest.searchHospital(); //conTest.setCon.next(); conTest.refreshPageSize(); //conTest.showParentManagementCode(); conTest.accContact = keiyaku3.id; //conTest.makepagerecords(); System.assertEquals(2, conTest.productInfoListview.size()); conTest.productInfoListview.sort(); conTest.accContact=null; conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null; conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); conTest.accContact='齐齐哈尔辛承医疗器械有限公司'; conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null; conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1); conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = null; conTest.save(); conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(3); conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); conTest.accContact='8037712'; conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1); conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); conTest.accContact = keiyaku4.id; conTest.dpc.Agent_Ref__c = sellerA.id; //conTest.makecontact(); conTest.keyword = 'Test01'; conTest.searchHospital(); conTest.productInfoListview[0].check=true; conTest.productInfoListview[0].pro.Id = null; conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200; conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1); conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1); conTest.save(); } @isTest static void updown() { initAcData(); PageReference page = new PageReference('/apex/AgencyCampaign'); System.Test.setCurrentPage(page); AgencyCampaignController conTest = new AgencyCampaignController(); conTest.pagesize = 2; conTest.init(); //conTest.product2s(); // System.assertEquals(3, conTest.productInfoListview.size()); //conTest.setCon.next(); conTest.refreshPageSize(); //conTest.showParentManagementCode(); conTest.searchHospital(); conTest.moveToNext(); conTest.moveToLast(); conTest.moveToPrevious(); conTest.pagesize = 1; conTest.moveToLast(); //System.assertEquals(2, conTest.productInfoListview.size()); } }