@isTest
private class SampleInventorySectionControllerTest {
    static testMethod void testSample_01(){
        // 客户记录类型
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '办事处'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 办事处 recodetype');
        }
        // 客户
        Account account2 = new Account();
		account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
        Account Agency = new Account();
        Agency.RecordTypeId                = rectCo[0].Id;
        Agency.Name                        = 'Katsu テスト';
        Agency.Quolified_Approve_Status__c = 'Draft';
        Agency.If_Need_Quolified__c        = true;
        Agency.ParentId = account2.Id;
        insert Agency;

        // 产品
        Product2 product = new Product2();
        product.Name                    = 'test01';
        product.ProductCode             = 'n011';
        product.Packing_list_manual__c  = 5;
        product.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product.Asset_Model_No__c       = 'n01';
        product.Whether_Sample__c       = true;
        product.SFDA_Status__c          = '有効';
        insert product;

        Product2 product1 = new Product2();
        product1.Name                    = 'test012';
        product1.ProductCode             = 'n0112';
        product1.Packing_list_manual__c  = 5;
        product1.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product1.Asset_Model_No__c       = 'n011';
        product1.Whether_Sample__c       = true;
        product1.SFDA_Status__c          = '有効';
        insert product1;
        
        Product2 product2 = new Product2();
        product2.Name                    = 'test012213';
        product2.ProductCode             = 'n011232';
        product2.Packing_list_manual__c  = 5;
        product2.SFDA_Expiration_Date__c = Date.today().addDays(-1);
        product2.Asset_Model_No__c       = 'n0111';
        product2.Whether_Sample__c       = true;
        product2.SFDA_Status__c          = '有効';
        insert product2;

        //样本库存表
        Sample_inventory_sheet__c samInventorySheet = new Sample_inventory_sheet__c();
        samInventorySheet.ProductCode__c   = product.ProductCode;
        samInventorySheet.Agency__c        = Agency.Id;
        samInventorySheet.Inventory__c     = 150;
        samInventorySheet.ValidTo__c       = Date.today().addDays(1);
        samInventorySheet.Pro_Model__c     = product.Asset_Model_No__c;
        insert samInventorySheet;
        Sample_inventory_sheet__c samInventorySheet1 = new Sample_inventory_sheet__c();
        samInventorySheet1.ProductCode__c   = product.ProductCode;
        samInventorySheet1.Agency__c        = Agency.Id;
        samInventorySheet1.Inventory__c     = 150;
        samInventorySheet1.ValidTo__c       = Date.today().addDays(-1);
        samInventorySheet1.Pro_Model__c     = product.Asset_Model_No__c;
        insert samInventorySheet1;
        Sample_inventory_sheet__c samInventorySheet4 = new Sample_inventory_sheet__c();
        samInventorySheet4.ProductCode__c   = product.ProductCode;
        samInventorySheet4.Agency__c        = Agency.Id;
        samInventorySheet4.Inventory__c     = 150;
        samInventorySheet4.ValidTo__c       = Date.today().addDays(1);
        samInventorySheet4.Pro_Model__c     = product.Asset_Model_No__c;
        insert samInventorySheet4;

        Sample_inventory_sheet__c samInventorySheet2 = new Sample_inventory_sheet__c();
        samInventorySheet2.ProductCode__c   = product1.ProductCode;
        samInventorySheet2.Agency__c        = Agency.Id;
        samInventorySheet2.Inventory__c     = 150;
        samInventorySheet2.ValidTo__c       = Date.today().addDays(1);
        samInventorySheet2.Pro_Model__c     = product1.Asset_Model_No__c;
        insert samInventorySheet2;

        Sample_inventory_sheet__c samInventorySheet3 = new Sample_inventory_sheet__c();
        samInventorySheet3.ProductCode__c   = product2.ProductCode;
        samInventorySheet3.Agency__c        = Agency.Id;
        samInventorySheet3.Inventory__c     = 150;
        samInventorySheet3.ValidTo__c      = Date.today().addDays(-1);
        samInventorySheet3.Pro_Model__c     = product2.Asset_Model_No__c;
        insert samInventorySheet3;

        ApexPages.currentPage().getParameters().put('accid', Agency.Id);
        SampleInventorySectionController samSection = new SampleInventorySectionController(new ApexPages.StandardController(Agency));
        samSection.init();
    }

}