@istest
public class LexArriveGoodsMainControllerTest {
    @IsTest
    static void lexArriveGoodsMainControllerTest1(){
        User myUser_test = new User();
        Account myAccount1;
        Contact core;
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true); 
        insert n;
        System.runAs(currentUser){
            Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id ,AgentCode_Ext__c = '9999900');
            insert myAccount1;
            core = new Contact(email='jplumber@salesforce.com',
            firstname='Joe',
            lastname='Plumber',
            accountid=myAccount1.id);
            insert core;
            myUser_test = New User(
                ContactId = core.id,
                Alias = 'newUser',
                Email='newuser@testorg.com',
                EmailEncodingKey='UTF-8',
                LastName='testUser',
                LanguageLocaleKey='zh_CN',
                LocaleSidKey='zh_CN',
                ProfileId = prof.Id,
                TimeZoneSidKey='Asia/Shanghai',
                UserName='testUser@testorg.com',
                Work_Location__c='北京');
            insert myUser_test;
        }
        System.runAs(myUser_test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Manual_Entry__c = false);
            insert new Product2[]{prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c(
                Name='OCM_01_001',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            Consumable_order__c Order2 = new Consumable_order__c(
                Name='OCM_01_002',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            insert new Consumable_order__c[] {Order1, Order2};

            //明细1
            Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
            createDetail.name = 'Too001';
            createDetail.Consumable_Product__c = pro1.id;
            createDetail.Dealer_Custom_Price__c = 999.00;
            createDetail.Consumable_count__c = 3;
            createDetail.Consumable_order__c =  Order1.id;
            createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail;
            Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
            createDetail1.name = 'Too002';
            createDetail1.Consumable_Product__c = pro2.id;
            createDetail1.Consumable_order__c =  Order2.id;
            createDetail1.Dealer_Custom_Price__c = 999.00;
            createDetail1.Consumable_count__c = 4;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail1;

            //订单明细
            Consumable_order_details2__c Orderdet1 =  new Consumable_order_details2__c(
                Name='OCM_01_001001',
                Consumable_order_minor__c = Order1.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet2 =  new Consumable_order_details2__c(
                Name='OCM_01_001002',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet3 =  new Consumable_order_details2__c(
                Name='OCM_01_001003',
                Consumable_order_minor__c = Order1.Id,
                //Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet4 =  new Consumable_order_details2__c(
                Name='OCM_01_001004',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2, Orderdet3, Orderdet4};

            LexArriveGoodsMainController.init();
            LexArriveGoodsMainController.searchConsumableorderdetails('Too001', null, myAccount1.Id, '北京', 'ET');
        }
    }
}