@isTest private class ConsumableSampleApplyControllerTest { //新建报价委托,填入单品一个,set品一个,保存 @isTest static void test01() { User user = new User(Test_staff__c = true); user.LastName = '_サンブリッジ'; user.FirstName = 'う'; user.Alias = 'う'; user.Email = 'olympustest03@sunbridge.com'; user.Username = 'olympustest03@sunbridge.com'; user.CommunityNickname = 'う'; user.IsActive = true; user.EmailEncodingKey = 'ISO-2022-JP'; user.TimeZoneSidKey = 'Asia/Tokyo'; user.LocaleSidKey = 'ja_JP'; user.LanguageLocaleKey = 'ja'; user.ProfileId = System.Label.ProfileId_SystemAdmin; user.Job_Category__c = '销售推广'; user.Province__c = '上海市'; user.Use_Start_Date__c = Date.today().addMonths(-6); insert user; // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Contact con = new Contact(RecordTypeId='012C600000003IeIAI');//niwu changed con.LastName = 'test1'; con.FirstName='ZZ'; con.AccountId = dep.Id; insert con; Product2 product1 = new Product2(); product1.Name = '00107:高频电极,按钮形,4Fr.,软性'; product1.SFDA_Status__c = '有効'; product1.Manual_Entry__c = false; product1.Asset_Model_No__c = '00107'; product1.ProductCode = '00107'; product1.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product1.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product1.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product1.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product1.Intra_Trade_List_RMB_1__c=2150; product1.Intra_Trade_List_RMB_2__c=2150; product1.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product1.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product1.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product1.Intra_Trade_Cost_RMB_1__c=10; product1.Intra_Trade_Cost_RMB_2__c=10; Product2 product2 = new Product2(); product2.Name = '00103:软管接头'; product2.SFDA_Status__c = '有効'; product2.Manual_Entry__c = false; product2.Asset_Model_No__c = '00103'; product2.ProductCode = '00103'; product2.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product2.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product2.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product2.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product2.Intra_Trade_List_RMB_1__c=170; product2.Intra_Trade_List_RMB_2__c=170; product2.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product2.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product2.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product2.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product2.Intra_Trade_Cost_RMB_1__c=10; product2.Intra_Trade_Cost_RMB_2__c=10; Product2 product3 = new Product2(); product3.Name = '00102.1:旋阀,免维护'; product3.SFDA_Status__c = '有効'; product3.Manual_Entry__c = false; product3.Asset_Model_No__c = '00102.1'; product3.ProductCode = '00102.1'; product3.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product3.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product3.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product3.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product3.Intra_Trade_List_RMB_1__c=920; product3.Intra_Trade_List_RMB_2__c=920; product3.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product3.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product3.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product3.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product3.Intra_Trade_Cost_RMB_1__c=10; product3.Intra_Trade_Cost_RMB_2__c=10; insert new Product2[] {product1,product2,product3}; Pricebook2 pricebook = ControllerUtil.getStandardPricebook(); PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id); entry2.UnitPrice = 0; entry2.IsActive = true; entry2.UseStandardPrice = false; entry2.CurrencyIsoCode = 'CNY'; PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id); entry3.UnitPrice = 0; entry3.IsActive = true; entry3.UseStandardPrice = false; entry3.CurrencyIsoCode = 'CNY'; insert new PricebookEntry[] {entry1,entry2,entry3}; Date now = Date.today(); PageReference page = new PageReference('/apex/ConsumableSampleApply'); System.Test.setCurrentPage(page); ConsumableSampleApplyController controller = new ConsumableSampleApplyController(); //初始化 controller.init(); System.assertEquals(null, controller.quo.Contact__c); System.assertEquals(null, controller.quo.Account__c); System.assertEquals(null, controller.quo.Expect_Arrive_Date__c); System.assertEquals(null, controller.quo.Purpose__c); System.assertEquals(null, controller.quo.Reason__c); System.assertEquals('草案中', controller.quo.Process_Status__c); System.assertEquals('CNY', controller.quo.CurrencyIsoCode); System.assertEquals(null, controller.activities[0].Asset_Model); controller.quo.Contact__c = con.Id; controller.quo.Expect_Arrive_Date__c = now; controller.quo.Purpose__c = 'test purpose'; controller.quo.Reason__c = 'test note'; controller.activities[0].lineNo = 0; controller.activities[0].Asset_Model = '00107'; controller.activities[0].pageObject.SFDA_Status__c = '有効'; controller.activities[0].pageObject.Name__c = '00107:高频电极,按钮形,4Fr.,软性'; controller.activities[0].pageObject.Product2__c = product1.Id; controller.activities[0].pageObject.Quantity__c = 1; controller.activities[0].ListPrice_Page = 2150; controller.Save(); ConsumableSample__c[] irais = [select Id, Name, Contact__c, Account__c, Expect_Arrive_Date__c, Purpose__c, Process_Status__c, Reason__c from ConsumableSample__c where Contact__c = :con.Id]; ConsumableSampleLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c from ConsumableSampleLineItem__c where ConsumableSample__c = :irais[0].Id order by Item_Order__c]; System.assertEquals(con.Id, irais[0].Contact__c); System.assertEquals(dep.Id, irais[0].Account__c); System.assertEquals(now, irais[0].Expect_Arrive_Date__c); System.assertEquals('test purpose', irais[0].Purpose__c); System.assertEquals('草案中', irais[0].Process_Status__c); System.assertEquals('test note', irais[0].Reason__c); System.assertEquals('00107', items[0].Asset_Model_No__c); System.assertEquals('有効', items[0].SFDA_Status__c); System.assertEquals('00107:高频电极,按钮形,4Fr.,软性', items[0].Name__c); System.assertEquals(1, items[0].Quantity__c); System.assertEquals(2150, items[0].ListPrice__c); System.assertEquals('00107', items[0].ProductCode__c); System.assertEquals(product1.Id, items[0].Product2__c); controller.approvalBtn(); } //既存报价委托,有一条既存明细,修改既存明细的数量,添加set品一个,保存 @isTest static void test02() { // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Contact con = new Contact(RecordTypeId='012C600000003IeIAI');//niwu changed con.LastName = 'test1'; con.FirstName='ZZ'; con.AccountId = dep.Id; insert con; Product2 product1 = new Product2(); product1.Name = '00107:高频电极,按钮形,4Fr.,软性'; product1.SFDA_Status__c = '有効'; product1.Manual_Entry__c = false; product1.Asset_Model_No__c = '00107'; product1.ProductCode = '00107'; product1.Foreign_Trade_List_US_Date1__c=Date.today().addDays(-1); product1.Foreign_Trade_List_US_Date2__c=Date.today().addDays(-1); product1.Foreign_Trade_List_US_End_Date1__c=Date.today().addDays(1); product1.Foreign_Trade_List_US_End_Date2__c=Date.today().addDays(1); product1.Foreign_Trade_List_US_1__c=2150; product1.Foreign_Trade_List_US_2__c=2150; product1.Foreign_Trade_Cost_US_Date1__c=Date.today().addDays(-1); product1.Foreign_Trade_Cost_US_Date2__c=Date.today().addDays(-1); product1.Foreign_Trade_Cost_US_End_Date1__c=Date.today().addDays(1); product1.Foreign_Trade_Cost_US_End_Date2__c=Date.today().addDays(1); product1.Foreign_Trade_Cost_US_1__c=10; product1.Foreign_Trade_Cost_US_2__c=10; Product2 product2 = new Product2(); product2.Name = '00103:软管接头'; product2.SFDA_Status__c = '有効'; product2.Manual_Entry__c = false; product2.Asset_Model_No__c = '00103'; product2.ProductCode = '00103'; product2.Foreign_Trade_List_US_Date1__c=Date.today().addDays(-1); product2.Foreign_Trade_List_US_Date2__c=Date.today().addDays(-1); product2.Foreign_Trade_List_US_End_Date1__c=Date.today().addDays(1); product2.Foreign_Trade_List_US_End_Date2__c=Date.today().addDays(1); product2.Foreign_Trade_List_US_1__c=170; product2.Foreign_Trade_List_US_2__c=170; product2.Foreign_Trade_Cost_US_Date1__c=Date.today().addDays(-1); product2.Foreign_Trade_Cost_US_Date2__c=Date.today().addDays(-1); product2.Foreign_Trade_Cost_US_End_Date1__c=Date.today().addDays(1); product2.Foreign_Trade_Cost_US_End_Date2__c=Date.today().addDays(1); product2.Foreign_Trade_Cost_US_1__c=10; product2.Foreign_Trade_Cost_US_2__c=10; Product2 product3 = new Product2(); product3.Name = '00102.1:旋阀,免维护'; product3.SFDA_Status__c = '有効'; product3.Manual_Entry__c = false; product3.Asset_Model_No__c = '00102.1'; product3.ProductCode = '00102.1'; product3.Foreign_Trade_List_US_Date1__c=Date.today().addDays(-1); product3.Foreign_Trade_List_US_Date2__c=Date.today().addDays(-1); product3.Foreign_Trade_List_US_End_Date1__c=Date.today().addDays(1); product3.Foreign_Trade_List_US_End_Date2__c=Date.today().addDays(1); product3.Foreign_Trade_List_US_1__c=920; product3.Foreign_Trade_List_US_2__c=920; product3.Foreign_Trade_Cost_US_Date1__c=Date.today().addDays(-1); product3.Foreign_Trade_Cost_US_Date2__c=Date.today().addDays(-1); product3.Foreign_Trade_Cost_US_End_Date1__c=Date.today().addDays(1); product3.Foreign_Trade_Cost_US_End_Date2__c=Date.today().addDays(1); product3.Foreign_Trade_Cost_US_1__c=10; product3.Foreign_Trade_Cost_US_2__c=10; insert new Product2[] {product1,product2,product3}; Pricebook2 pricebook = ControllerUtil.getStandardPricebook(); PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'USD'; PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id); entry2.UnitPrice = 0; entry2.IsActive = true; entry2.UseStandardPrice = false; entry2.CurrencyIsoCode = 'USD'; PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id); entry3.UnitPrice = 0; entry3.IsActive = true; entry3.UseStandardPrice = false; entry3.CurrencyIsoCode = 'USD'; insert new PricebookEntry[] {entry1,entry2,entry3}; ConsumableSample__c irai = new ConsumableSample__c(); irai.Contact__c = con.Id; irai.Account__c = dep.Id; irai.Process_Status__c = '草案中'; irai.Expect_Arrive_Date__c = Date.today(); irai.Purpose__c = 'test purpose'; irai.Reason__c = 'test note'; irai.CurrencyIsoCode = 'USD'; insert irai; ConsumableSampleLineItem__c item1 = new ConsumableSampleLineItem__c(); item1.SFDA_Status__c = '有効'; item1.Name__c = '00107:高频电极,按钮形,4Fr.,软性'; item1.Quantity__c = 1; item1.ListPrice__c = 2150; item1.Product2__c = product1.Id; item1.ConsumableSample__c = irai.Id; item1.Item_Order__c = 1; insert item1; PageReference page = new PageReference('/apex/ConsumableSampleApply?id=' + irai.Id); System.Test.setCurrentPage(page); ConsumableSampleApplyController controller = new ConsumableSampleApplyController(); //初始化 controller.init(); System.assertEquals(con.Id, controller.quo.Contact__c); System.assertEquals('test purpose', controller.quo.Purpose__c); System.assertEquals('test note', controller.quo.Reason__c); System.assertEquals(0, controller.activities[0].lineNo); System.assertEquals('00107', controller.activities[0].Asset_Model); System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c); System.assertEquals('00107:高频电极,按钮形,4Fr.,软性', controller.activities[0].pageObject.Name__c); System.assertEquals(1, controller.activities[0].pageObject.Quantity__c); System.assertEquals(2150, controller.activities[0].ListPrice_Page); System.assertEquals(product1.Id, controller.activities[0].pageObject.Product2__c); controller.quo.Purpose__c = 'test purpose1'; controller.activities[0].pageObject.Quantity__c = 2; controller.OppReflection(); ConsumableSample__c[] irais = [select Id, Name, Contact__c, Account__c, Expect_Arrive_Date__c, Purpose__c, Process_Status__c, Reason__c from ConsumableSample__c where Contact__c = :con.Id]; ConsumableSampleLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c from ConsumableSampleLineItem__c where ConsumableSample__c = :irais[0].Id order by Item_Order__c]; system.assertEquals('test purpose1', irais[0].Purpose__c); system.assertEquals('00107', items[0].Asset_Model_No__c); system.assertEquals('有効', items[0].SFDA_Status__c); system.assertEquals('00107:高频电极,按钮形,4Fr.,软性', items[0].Name__c); system.assertEquals(2, items[0].Quantity__c); system.assertEquals(2150, items[0].ListPrice__c); system.assertEquals('00107', items[0].ProductCode__c); system.assertEquals(product1.Id, items[0].Product2__c); } //再报价 static testMethod void test03() { User user = new User(Test_staff__c = true); user.LastName = '_サンブリッジ'; user.FirstName = 'う'; user.Alias = 'う'; user.Email = 'olympustest03@sunbridge.com'; user.Username = 'olympustest03@sunbridge.com'; user.CommunityNickname = 'う'; user.IsActive = true; user.EmailEncodingKey = 'ISO-2022-JP'; user.TimeZoneSidKey = 'Asia/Tokyo'; user.LocaleSidKey = 'ja_JP'; user.LanguageLocaleKey = 'ja'; user.ProfileId = System.Label.ProfileId_SystemAdmin; user.Job_Category__c = '销售推广'; user.Province__c = '上海市'; user.Use_Start_Date__c = Date.today().addMonths(-6); insert user; // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Contact con = new Contact(RecordTypeId='012C600000003IeIAI');//niwu changed con.LastName = 'test1'; con.FirstName='ZZ'; con.AccountId = dep.Id; insert con; Product2 product1 = new Product2(); product1.Name = '00107:高频电极,按钮形,4Fr.,软性'; product1.SFDA_Status__c = '有効'; product1.Manual_Entry__c = false; product1.Asset_Model_No__c = '00107'; product1.ProductCode = '00107'; product1.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product1.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product1.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product1.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product1.Intra_Trade_List_RMB_1__c=2150; product1.Intra_Trade_List_RMB_2__c=2150; product1.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product1.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product1.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product1.Intra_Trade_Cost_RMB_1__c=10; product1.Intra_Trade_Cost_RMB_2__c=10; Product2 product2 = new Product2(); product2.Name = '00103:软管接头'; product2.SFDA_Status__c = '有効'; product2.Manual_Entry__c = false; product2.Asset_Model_No__c = '00103'; product2.ProductCode = '00103'; product2.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product2.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product2.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product2.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product2.Intra_Trade_List_RMB_1__c=170; product2.Intra_Trade_List_RMB_2__c=170; product2.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product2.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product2.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product2.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product2.Intra_Trade_Cost_RMB_1__c=10; product2.Intra_Trade_Cost_RMB_2__c=10; insert new Product2[] {product1,product2}; Pricebook2 pricebook = ControllerUtil.getStandardPricebook(); PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id); entry2.UnitPrice = 0; entry2.IsActive = true; entry2.UseStandardPrice = false; entry2.CurrencyIsoCode = 'CNY'; insert new PricebookEntry[] {entry1,entry2}; ConsumableSample__c irai = new ConsumableSample__c(); irai.Contact__c = con.Id; irai.Account__c = dep.Id; irai.Process_Status__c = '草案中'; irai.Expect_Arrive_Date__c = Date.today(); irai.Purpose__c = 'test purpose'; irai.Reason__c = 'test note'; insert irai; ConsumableSampleLineItem__c item1 = new ConsumableSampleLineItem__c(); item1.SFDA_Status__c = '有効'; item1.Name__c = '00107:高频电极,按钮形,4Fr.,软性'; item1.Quantity__c = 1; item1.ListPrice__c = 2150; item1.Product2__c = product1.Id; item1.ConsumableSample__c = irai.Id; item1.Item_Order__c = 1; insert item1; ConsumableSampleLineItem__c item2 = new ConsumableSampleLineItem__c(); item2.SFDA_Status__c = '有効'; item2.Name__c = '00103:软管接头'; item2.Quantity__c = 10; item2.ListPrice__c = 170; item2.Product2__c = product2.Id; item2.ConsumableSample__c = irai.Id; item2.Item_Order__c = 2; insert item2; PageReference page = new PageReference('/apex/ConsumableSampleApply?copyid=' + irai.Id); System.Test.setCurrentPage(page); ConsumableSampleApplyController controller = new ConsumableSampleApplyController(); //初始化 controller.init(); System.assertEquals('CNY', controller.quo.CurrencyIsoCode); System.assertEquals('草案中', controller.quo.Process_Status__c); System.assertEquals(null, controller.quo.Contact__c); System.assertEquals(null, controller.quo.Account__c); System.assertEquals(null, controller.quo.Expect_Arrive_Date__c); System.assertEquals('', controller.quo.Purpose__c ); System.assertEquals('', controller.quo.Reason__c); System.assertEquals(0, controller.activities[0].lineNo); System.assertEquals('00107', controller.activities[0].Asset_Model); System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c); System.assertEquals('00107:高频电极,按钮形,4Fr.,软性', controller.activities[0].pageObject.Name__c); System.assertEquals(1, controller.activities[0].pageObject.Quantity__c); System.assertEquals(2150, controller.activities[0].ListPrice_Page); System.assertEquals(product1.Id, controller.activities[0].pageObject.Product2__c); System.assertEquals(1, controller.activities[1].lineNo); System.assertEquals('00103', controller.activities[1].Asset_Model); System.assertEquals('有効', controller.activities[1].pageObject.SFDA_Status__c); System.assertEquals('00103:软管接头', controller.activities[1].pageObject.Name__c); System.assertEquals(10, controller.activities[1].pageObject.Quantity__c); System.assertEquals(170, controller.activities[1].ListPrice_Page); System.assertEquals(product2.Id, controller.activities[1].pageObject.Product2__c); controller.quo.Contact__c = con.Id; controller.quo.Expect_Arrive_Date__c = Date.today(); controller.quo.Purpose__c = 'Purpose__c'; controller.quo.Reason__c = 'Reason__c'; controller.Save(); ConsumableSample__c[] irais = [select Id, Name, Contact__c, Account__c, Expect_Arrive_Date__c, Purpose__c, Process_Status__c, Reason__c from ConsumableSample__c where Contact__c = :con.Id order by CreatedDate]; ConsumableSampleLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c from ConsumableSampleLineItem__c where ConsumableSample__c = :irais[1].Id order by Item_Order__c]; System.assertEquals(con.Id, irais[1].Contact__c); System.assertEquals(dep.Id, irais[1].Account__c); System.assertEquals('Purpose__c', irais[1].Purpose__c); System.assertEquals('Reason__c', irais[1].Reason__c); System.assertEquals('草案中', irais[1].Process_Status__c); System.assertEquals('00107', items[0].Asset_Model_No__c); System.assertEquals('有効', items[0].SFDA_Status__c); System.assertEquals('00107:高频电极,按钮形,4Fr.,软性', items[0].Name__c); System.assertEquals(1, items[0].Quantity__c); System.assertEquals(2150, items[0].ListPrice__c); System.assertEquals('00107', items[0].ProductCode__c); System.assertEquals(product1.Id, items[0].Product2__c); System.assertEquals('00103', items[1].Asset_Model_No__c); System.assertEquals('有効', items[1].SFDA_Status__c); System.assertEquals('00103:软管接头', items[1].Name__c); System.assertEquals(10, items[1].Quantity__c); System.assertEquals(170, items[1].ListPrice__c); System.assertEquals('00103', items[1].ProductCode__c); System.assertEquals(product2.Id, items[1].Product2__c); } //新建报价委托,excel导入明细一条,保存;再excel导入明细三条,委托 static testMethod void test04() { User user = new User(Test_staff__c = true); user.LastName = '_サンブリッジ'; user.FirstName = 'う'; user.Alias = 'う'; user.Email = 'olympustest03@sunbridge.com'; user.Username = 'olympustest03@sunbridge.com'; user.CommunityNickname = 'う'; user.IsActive = true; user.EmailEncodingKey = 'ISO-2022-JP'; user.TimeZoneSidKey = 'Asia/Tokyo'; user.LocaleSidKey = 'ja_JP'; user.LanguageLocaleKey = 'ja'; user.ProfileId = System.Label.ProfileId_SystemAdmin; user.Job_Category__c = '销售推广'; user.Province__c = '上海市'; user.Use_Start_Date__c = Date.today().addMonths(-6); insert user; // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Contact con = new Contact(RecordTypeId='012C600000003IeIAI');//niwu changed con.LastName = 'test1'; con.FirstName='ZZ'; con.AccountId = dep.Id; insert con; Product2 product1 = new Product2(); product1.Name = '00107:高频电极,按钮形,4Fr.,软性'; product1.SFDA_Status__c = '有効'; product1.Manual_Entry__c = false; product1.Asset_Model_No__c = '00107'; product1.ProductCode = '00107'; product1.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product1.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product1.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product1.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product1.Intra_Trade_List_RMB_1__c=2150; product1.Intra_Trade_List_RMB_2__c=2150; product1.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product1.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product1.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product1.Intra_Trade_Cost_RMB_1__c=10; product1.Intra_Trade_Cost_RMB_2__c=10; Product2 product2 = new Product2(); product2.Name = '00103:软管接头'; product2.SFDA_Status__c = '有効'; product2.Manual_Entry__c = false; product2.Asset_Model_No__c = '00103'; product2.ProductCode = '00103'; product2.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product2.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product2.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product2.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product2.Intra_Trade_List_RMB_1__c=170; product2.Intra_Trade_List_RMB_2__c=170; product2.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product2.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product2.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product2.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product2.Intra_Trade_Cost_RMB_1__c=10; product2.Intra_Trade_Cost_RMB_2__c=10; Product2 product3 = new Product2(); product3.Name = '00102.1:旋阀,免维护'; product3.SFDA_Status__c = '有効'; product3.Manual_Entry__c = false; product3.Asset_Model_No__c = '00102.1'; product3.ProductCode = '00102.1'; product3.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1); product3.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1); product3.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1); product3.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1); product3.Intra_Trade_List_RMB_1__c=920; product3.Intra_Trade_List_RMB_2__c=920; product3.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1); product3.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1); product3.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1); product3.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1); product3.Intra_Trade_Cost_RMB_1__c=10; product3.Intra_Trade_Cost_RMB_2__c=10; insert new Product2[] {product1,product2,product3}; Pricebook2 pricebook = ControllerUtil.getStandardPricebook(); PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id); entry2.UnitPrice = 0; entry2.IsActive = true; entry2.UseStandardPrice = false; entry2.CurrencyIsoCode = 'CNY'; PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id); entry3.UnitPrice = 0; entry3.IsActive = true; entry3.UseStandardPrice = false; entry3.CurrencyIsoCode = 'CNY'; insert new PricebookEntry[] {entry1,entry2,entry3}; PageReference page = new PageReference('/apex/ConsumableSampleApply'); System.Test.setCurrentPage(page); ConsumableSampleApplyController controller = new ConsumableSampleApplyController(); //初始化 controller.init(); controller.quo.Contact__c = con.Id; controller.quo.Expect_Arrive_Date__c = Date.today(); controller.quo.Purpose__c = 'test purpose'; controller.quo.Reason__c = 'test note'; controller.excel_text = '00103\t10'; controller.excelImport(); System.assertEquals('00103', controller.activities[0].Asset_Model); System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c); System.assertEquals('00103:软管接头', controller.activities[0].pageObject.Name__c); System.assertEquals(10, controller.activities[0].pageObject.Quantity__c); System.assertEquals(product2.Id, controller.activities[0].pageObject.Product2__c); controller.Save(); ConsumableSample__c[] irais = [select Id, Name, Contact__c, Account__c, Expect_Arrive_Date__c, Purpose__c, Process_Status__c, Reason__c from ConsumableSample__c where Contact__c = :con.Id]; ConsumableSampleLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c from ConsumableSampleLineItem__c where ConsumableSample__c = :irais[0].Id order by Item_Order__c]; System.assertEquals(con.Id, irais[0].Contact__c); System.assertEquals(dep.Id, irais[0].Account__c); System.assertEquals('test purpose', irais[0].Purpose__c); System.assertEquals('test note', irais[0].Reason__c); System.assertEquals('00103', items[0].Asset_Model_No__c); System.assertEquals('有効', items[0].SFDA_Status__c); System.assertEquals('00103:软管接头', items[0].Name__c); System.assertEquals(10, items[0].Quantity__c); System.assertEquals('00103', items[0].ProductCode__c); System.assertEquals(product2.Id, items[0].Product2__c); controller.excel_text = '00103\t10\n00102.1\t10\n00107\t2'; controller.excelImport(); System.assertEquals('00103', controller.activities[0].Asset_Model); System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c); System.assertEquals('00103:软管接头', controller.activities[0].pageObject.Name__c); System.assertEquals(10, controller.activities[0].pageObject.Quantity__c); System.assertEquals(product2.Id, controller.activities[0].pageObject.Product2__c); System.assertEquals('00103', controller.activities[1].Asset_Model); System.assertEquals('有効', controller.activities[1].pageObject.SFDA_Status__c); System.assertEquals('00103:软管接头', controller.activities[1].pageObject.Name__c); System.assertEquals(10, controller.activities[1].pageObject.Quantity__c); System.assertEquals(product2.Id, controller.activities[1].pageObject.Product2__c); System.assertEquals('00102.1', controller.activities[2].Asset_Model); System.assertEquals('有効', controller.activities[2].pageObject.SFDA_Status__c); System.assertEquals('00102.1:旋阀,免维护', controller.activities[2].pageObject.Name__c); System.assertEquals(10, controller.activities[2].pageObject.Quantity__c); System.assertEquals(product3.Id, controller.activities[2].pageObject.Product2__c); System.assertEquals('00107', controller.activities[3].Asset_Model); System.assertEquals('有効', controller.activities[3].pageObject.SFDA_Status__c); System.assertEquals('00107:高频电极,按钮形,4Fr.,软性', controller.activities[3].pageObject.Name__c); System.assertEquals(2, controller.activities[3].pageObject.Quantity__c); System.assertEquals(product1.Id, controller.activities[3].pageObject.Product2__c); controller.Save(); ConsumableSample__c[] irais2 = [select Id, Name, Contact__c, Account__c, Expect_Arrive_Date__c, Purpose__c, Process_Status__c, Reason__c from ConsumableSample__c where Contact__c = :con.Id]; ConsumableSampleLineItem__c[] items2 = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c from ConsumableSampleLineItem__c where ConsumableSample__c = :irais[0].Id order by Item_Order__c]; System.assertEquals(con.Id, irais2[0].Contact__c); System.assertEquals(dep.Id, irais2[0].Account__c); System.assertEquals('test purpose', irais2[0].Purpose__c); System.assertEquals('test note', irais2[0].Reason__c); System.assertEquals('00103', items2[0].Asset_Model_No__c); System.assertEquals('有効', items2[0].SFDA_Status__c); System.assertEquals('00103:软管接头', items2[0].Name__c); System.assertEquals(10, items2[0].Quantity__c); System.assertEquals('00103', items2[0].ProductCode__c); System.assertEquals(product2.Id, items2[0].Product2__c); // 商品状态刷新 Product2 p2 = [select Id, SFDA_Status__c,Name from Product2 where Id = :product2.Id]; p2.SFDA_Status__c = '停止'; p2.Name = '00103:软管接头123'; update p2; controller.Save(); System.assertEquals(true, controller.errorflg); System.assertEquals('停止', controller.activities[0].pageObject.SFDA_Status__c); System.assertEquals('00103:软管接头123', controller.activities[0].pageObject.Name__c); } //其他单体函数 static testMethod void test05() { // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Contact con = new Contact(RecordTypeId='012C600000003IeIAI');//niwu changed con.LastName = 'test1'; con.FirstName='ZZ'; con.AccountId = dep.Id; insert con; ConsumableSample__c irai = new ConsumableSample__c(); irai.Contact__c = con.Id; irai.Account__c = dep.Id; irai.Process_Status__c = '草案中'; irai.Expect_Arrive_Date__c = Date.today(); irai.Purpose__c = 'test purpose'; irai.Reason__c = 'test note'; insert irai; PageReference page = new PageReference('/apex/ConsumableSampleApply?id=' + irai.Id); System.Test.setCurrentPage(page); ConsumableSampleApplyController controller = new ConsumableSampleApplyController(); controller.init(); controller.Back(); } }