@IsTest
private class LexTopPageControllerTest {
    @IsTest
    static void testMethod1(){
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true);
        insert n;
        Test.startTest();
        System.runAs(currentUser){
            LexTopPageController.initAgency();
            LexTopPageController.initPage(20, 1);
        }
        Test.stopTest();
    }

    @IsTest
    static void testMethod2(){
        user MyUser_Test;
        Account myAccount1;
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true);
        insert n;
        System.runAs(thisUser){
			Profile prof1 = [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;
			}
			StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
			
			RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
			Account olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus');
			insert olympus;
			myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888',Product_Limit_Date__c = 'Test07|3|100,Test08|10|50');
			insert myAccount1;
			Contact 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 = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '重庆');
			insert MyUser_Test;

		}
       
		system.runAs(MyUser_Test){
			//产品数据
	        Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        Product2 prod08 = new Product2(Name='Test08',ProductCode='Test08',Asset_Model_No__c = 'Test08',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        Product2 prod09 = new Product2(Name='Test09',ProductCode='Test09',Asset_Model_No__c = 'Test09',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        insert new Product2[] {prod07,prod08,prod09};

			//制作产品
			Product2__c proG = new Product2__c(Name='MH-155:白平衡帽',OT_CODE_Text__c='Test001',Product2__c = prod07.Id);
			insert proG;
			Product2__c proH = new Product2__c(Name='MB-677:BNC电缆',OT_CODE_Text__c='Test002',Product2__c = prod08.Id);
			insert proH;
			Product2__c proF = new Product2__c(Name='TooMAJ-643R:水囊鞘管003',OT_CODE_Text__c='Test003',Product2__c = prod09.Id);
			insert proF;


			//订单
			Consumable_order__c order = new Consumable_order__c();
			order.Name = 'testMing';
			order.Order_status__c = '批准';
			order.RecordTypeid = System.Label.RT_ConOrder_Order;
			order.Dealer_Info__c = myAccount1.id;
			order.Inventory_date__c = Date.today();
        	order.Order_type__c = '订单';
			order.Order_ProType__c = 'ET';
			insert  order;
			//到货
			Consumable_order__c order2 = new Consumable_order__c();
			order2.Name = 'testMing1';
			order2.Order_status__c = '批准';
			order2.RecordTypeid = '01210000000c9dqAAA';
			order2.Dealer_Info__c = myAccount1.id;
        	order2.Order_type__c = '到货';
			order2.Order_ProType__c = 'ET';
			insert  order2;

			List<Consumable_order_details2__c> conList = new List<Consumable_order_details2__c>();
			//制作Consumable_order_details__c-------ProductCount
			// 销售
			Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c();
			dataForProductCount7.Bar_Code__c               = '123456789298k250AAAAA';
			dataForProductCount7.Sterilization_limit__c    = Date.today().addDays(2);
			dataForProductCount7.Arrive_date__c			  = Date.today();
			dataForProductCount7.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProductCount7.Consumable_Product__c     = proH.id;
			dataForProductCount7.Asset_Model_No__c         = proH.Asset_Model_No__c;
			dataForProductCount7.Box_Piece__c              = '盒';
            dataForProductCount7.Used_date__c = Date.today();
            dataForProductCount7.Consumable_order_minor__c = order.id;

			conList.add(dataForProductCount7);
			// 在库 过期 盒
			Consumable_order_details2__c dataForProduct = new Consumable_order_details2__c();
			dataForProduct.Bar_Code__c               = '123456789498k250BBBBB';
			dataForProduct.Sterilization_limit__c    = Date.today().addDays(-2);
			dataForProduct.Arrive_date__c			  = Date.today();
			dataForProduct.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProduct.Consumable_Product__c     = proF.id;
			dataForProduct.Asset_Model_No__c         = proF.Asset_Model_No__c;
			dataForProduct.Box_Piece__c              = '盒';
			dataForProduct.Consumable_order_minor__c = order.id;

			conList.add(dataForProduct);
			// 在库 过期 个
			Consumable_order_details2__c dataForProductCount3 = new Consumable_order_details2__c();
			dataForProductCount3.Bar_Code__c               = '123456788398k250CCCCC';
			dataForProductCount3.Sterilization_limit__c    = Date.today().addDays(-2);
			dataForProductCount3.Arrive_date__c			  = Date.today();
			dataForProductCount3.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProductCount3.Consumable_Product__c     = proG.id;
			dataForProductCount3.Asset_Model_No__c         = proG.Asset_Model_No__c;
            dataForProductCount3.Box_Piece__c              = '个';
            dataForProductCount3.RemoveBox_No__c = 1;
            dataForProductCount3.Consumable_order_minor__c = order.id;
			conList.add(dataForProductCount3);
			insert conList;
			
			//过期库存汇总信息 add by Wang Xueqin
			List<Consumable_order_details2__c> conList1 = new List<Consumable_order_details2__c>();
			Consumable_order_details2__c dataForProductCount4 = new Consumable_order_details2__c();
			dataForProductCount4.Bar_Code__c = '1001';
			dataForProductCount4.Arrive_date__c = Date.today();
			dataForProductCount4.Send_Date__c = null;
			dataForProductCount4.Used_date__c = null;
			dataForProductCount4.Return_date__c = null;
			dataForProductCount4.Lose_Flag__c = false;
			dataForProductCount4.Cancellation_Flag__c = false;
			dataForProductCount4.Consumable_Product__c = proG.Id;
			dataForProductCount4.Consumable_Arrived_order__c = order2.id;
			dataForProductCount4.Used_account__c = myAccount1.Id;
			dataForProductCount4.Sterilization_limit__c = Date.today().addDays(-2);
			dataForProductCount4.Box_Piece__c = '盒';
			conList1.add(dataForProductCount4);
			System.debug('conList1==>'+conList1);
			//查询所有过期库存
			Consumable_order_details2__c dataForProductCount5 = new Consumable_order_details2__c();
			dataForProductCount5.Bar_Code__c = '1002';
			dataForProductCount5.Arrive_date__c = Date.today();
			dataForProductCount5.Send_Date__c =  Date.today();
			dataForProductCount5.Used_date__c =  Date.today();
			dataForProductCount5.Return_date__c = null;
			dataForProductCount5.Lose_Flag__c = false;
			dataForProductCount5.Cancellation_Flag__c = false;
			dataForProductCount5.Consumable_Product__c = proG.Id;
			dataForProductCount5.Consumable_Arrived_order__c = order2.id;
			dataForProductCount5.Used_account__c = myAccount1.Id;
			dataForProductCount5.Sterilization_limit__c = Date.today().addDays(-2);
			dataForProductCount5.Box_Piece__c = '盒';
			conList1.add(dataForProductCount5);
			insert conList1; 
            Test.startTest();
            LexTopPageController.initAgency();
            LexTopPageController.initPage(20, 1);
            Test.stopTest();
        }
    }

    @IsTest
    static void testMethod3(){
        user MyUser_Test;
        Account myAccount1;
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true);
        insert n;
        System.runAs(thisUser){
			Profile prof1 = [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;
			}
			StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
			
			RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
			Account olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus');
			insert olympus;
			myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888');
			insert myAccount1;
			Contact 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 = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '重庆');
			insert MyUser_Test;

		}
       
		system.runAs(MyUser_Test){
			//产品数据
	        Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        Product2 prod08 = new Product2(Name='Test08',ProductCode='Test08',Asset_Model_No__c = 'Test08',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        Product2 prod09 = new Product2(Name='Test09',ProductCode='Test09',Asset_Model_No__c = 'Test09',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        insert new Product2[] {prod07,prod08,prod09};

			//制作产品
			Product2__c proG = new Product2__c(Name='MH-155:白平衡帽',OT_CODE_Text__c='Test001',Product2__c = prod07.Id);
			insert proG;
			Product2__c proH = new Product2__c(Name='MB-677:BNC电缆',OT_CODE_Text__c='Test002',Product2__c = prod08.Id);
			insert proH;
			Product2__c proF = new Product2__c(Name='TooMAJ-643R:水囊鞘管003',OT_CODE_Text__c='Test003',Product2__c = prod09.Id);
			insert proF;


			//订单
			Consumable_order__c order = new Consumable_order__c();
			order.Name = 'testMing';
			order.Order_status__c = '批准';
			order.RecordTypeid = System.Label.RT_ConOrder_Order;
			order.Dealer_Info__c = myAccount1.id;
			order.Inventory_date__c = Date.today();
        	order.Order_type__c = '订单';
			order.Order_ProType__c = 'ET';
			insert  order;
			//到货
			Consumable_order__c order2 = new Consumable_order__c();
			order2.Name = 'testMing1';
			order2.Order_status__c = '批准';
			order2.RecordTypeid = '01210000000c9dqAAA';
			order2.Dealer_Info__c = myAccount1.id;
        	order2.Order_type__c = '到货';
			order2.Order_ProType__c = 'ET';
			insert  order2;

			List<Consumable_order_details2__c> conList = new List<Consumable_order_details2__c>();
			//制作Consumable_order_details__c-------ProductCount
			// 销售
			Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c();
			dataForProductCount7.Bar_Code__c               = '123456789298k250AAAAA';
			dataForProductCount7.Sterilization_limit__c    = Date.today().addDays(2);
			dataForProductCount7.Arrive_date__c			  = Date.today();
			dataForProductCount7.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProductCount7.Consumable_Product__c     = proH.id;
			dataForProductCount7.Asset_Model_No__c         = proH.Asset_Model_No__c;
			dataForProductCount7.Box_Piece__c              = '个';
            dataForProductCount7.Used_date__c = Date.today();
            dataForProductCount7.Consumable_order_minor__c = order.id;

			conList.add(dataForProductCount7);
			// 在库 过期 盒
			Consumable_order_details2__c dataForProduct = new Consumable_order_details2__c();
			dataForProduct.Bar_Code__c               = '123456789498k250BBBBB';
			dataForProduct.Sterilization_limit__c    = Date.today().addDays(-2);
			dataForProduct.Arrive_date__c			  = Date.today();
			dataForProduct.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProduct.Consumable_Product__c     = proF.id;
			dataForProduct.Asset_Model_No__c         = proF.Asset_Model_No__c;
			dataForProduct.Box_Piece__c              = '个';
			dataForProduct.Consumable_order_minor__c = order.id;

			conList.add(dataForProduct);
			// 在库 过期 个
			Consumable_order_details2__c dataForProductCount3 = new Consumable_order_details2__c();
			dataForProductCount3.Bar_Code__c               = '123456788398k250CCCCC';
			dataForProductCount3.Sterilization_limit__c    = Date.today().addDays(-2);
			dataForProductCount3.Arrive_date__c			  = Date.today();
			dataForProductCount3.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProductCount3.Consumable_Product__c     = proG.id;
			dataForProductCount3.Asset_Model_No__c         = proG.Asset_Model_No__c;
            dataForProductCount3.Box_Piece__c              = '个';
            dataForProductCount3.RemoveBox_No__c = 1;
            dataForProductCount3.Consumable_order_minor__c = order.id;
			conList.add(dataForProductCount3);
			insert conList;
			
			//过期库存汇总信息 add by Wang Xueqin
			List<Consumable_order_details2__c> conList1 = new List<Consumable_order_details2__c>();
			Consumable_order_details2__c dataForProductCount4 = new Consumable_order_details2__c();
			dataForProductCount4.Bar_Code__c = '1001';
			dataForProductCount4.Arrive_date__c = Date.today();
			dataForProductCount4.Send_Date__c = null;
			dataForProductCount4.Used_date__c = null;
			dataForProductCount4.Return_date__c = null;
			dataForProductCount4.Lose_Flag__c = false;
			dataForProductCount4.Cancellation_Flag__c = false;
			dataForProductCount4.Consumable_Product__c = proG.Id;
			dataForProductCount4.Consumable_Arrived_order__c = order2.id;
			dataForProductCount4.Used_account__c = myAccount1.Id;
			dataForProductCount4.Sterilization_limit__c = Date.today().addDays(-2);
			dataForProductCount4.Box_Piece__c = '个';
			conList1.add(dataForProductCount4);
			System.debug('conList1==>'+conList1);
			//查询所有过期库存
			Consumable_order_details2__c dataForProductCount5 = new Consumable_order_details2__c();
			dataForProductCount5.Bar_Code__c = '1002';
			dataForProductCount5.Arrive_date__c = Date.today();
			dataForProductCount5.Send_Date__c =  Date.today();
			dataForProductCount5.Used_date__c =  Date.today();
			dataForProductCount5.Return_date__c = null;
			dataForProductCount5.Lose_Flag__c = false;
			dataForProductCount5.Cancellation_Flag__c = false;
			dataForProductCount5.Consumable_Product__c = proG.Id;
			dataForProductCount5.Consumable_Arrived_order__c = order2.id;
			dataForProductCount5.Used_account__c = myAccount1.Id;
			dataForProductCount5.Sterilization_limit__c = Date.today().addDays(-2);
			dataForProductCount5.Box_Piece__c = '个';
			conList1.add(dataForProductCount5);
			insert conList1; 
            Test.startTest();
            LexTopPageController.initAgency();
            LexTopPageController.initPage(20, 1);
            LexTopPageController.ConsumableorderdetailsInfo c1 = new LexTopPageController.ConsumableorderdetailsInfo(proG);
            c1.allnumber = 10;
            LexTopPageController.ConsumableorderdetailsInfo c2 = new LexTopPageController.ConsumableorderdetailsInfo(proH);
            c2.allnumber = 20;
            c1.compareTo(c2);
            c1.allnumber = 20;
            c2.allnumber = 10;
            c1.compareTo(c2);
            Test.stopTest();
        }
    }
    
}