@isTest
private class Product2HandlerTest {	
	@isTest 
	static void insertProduct2_1() {
		// 产品
        Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='SP',
                Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n05',
                ProductCode_Ext__c='pc05',Manual_Entry__c=false,
                StorageStatus__c = '',StorageStatusNo__c = 22,
                WhiteSpace__c = true);
        insert pro5;

        List<Product2> product2s = [select Id,Name,StorageStatus__c from Product2];

        System.assertEquals(1, product2s.size());
        System.assertEquals('22', product2s[0].StorageStatus__c);
	}

	@isTest 
	static void insertProduct2_2() {
		// 产品
        Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='SP',
                Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n05',
                ProductCode_Ext__c='pc05',Manual_Entry__c=false,
                StorageStatus__c = '',StorageStatusNo__c = 22,
                WhiteSpace__c = false);
        insert pro5;
        List<Product2> product2s = [select Id,Name,StorageStatus__c from Product2];

        System.assertEquals(1, product2s.size());
        System.assertEquals(null, product2s[0].StorageStatus__c);

        pro5.WhiteSpace__c = true;
        update pro5;
        product2s = [select Id,Name,StorageStatus__c from Product2];

        System.assertEquals(1, product2s.size());
        System.assertEquals('22', product2s[0].StorageStatus__c);

	}
        @isTest
        static void insertProduct2_3() {
                // 产品
        List<String> noNewList = new List<String>();
        Product2 pro5 = new Product2(Asset_Model_No__c = 'AC20221108',
                Name='name05',IsActive=true,Family='SP',
                Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n05',
                ProductCode_Ext__c='pc05',Manual_Entry__c=false,
                StorageStatus__c = '',StorageStatusNo__c = 22,
                WhiteSpace__c = true);
        insert pro5;
        noNewList.add(pro5.Asset_Model_No__c);
        List<Product2> prdList = [select Id, Name,Asset_Model_No__c,MDM_Name__c,
                                    Maintenance_Price_Year__c,Extend_new_product_gurantee_MD__c,
                                    Extend_Gurantee_Start_MD__c,Extend_Gurantee_End_MD__c,
                                    Entend_gurantee_period_MD__c,Extend_new_product_gurantee__c,
                                    Extend_Gurantee_Start__c,Extend_Gurantee_End__c,Entend_gurantee_period__c,
                                    CanNotCancelledGurantee__c,Service_Category1__c,
                                    Service_Category2__c,Service_Category3__c,
                                    Service_Category4__c,Service_Category5__c,
                                    Service_Category6__c,Service_Category7__c,
                                    Can_Repair__c,RepairListPriceLevelA__c,
                                    RepairListPriceLevelB__c,RepairListPriceLevelC__c,
                                    PartSupplyFinishDate__c,EndSaleDate__c,ProductClass__c,ProductCategory__c,
                                    Period_Filter_Classify1__c,Period_Filter_Classify2__c
                                    from Product2
                                    where Asset_Model_No__c in :noNewList
                                    order by LastModifiedDate desc];

        List<Product2> product2s = [select Id,Name,StorageStatus__c from Product2];

        System.assertEquals(1, product2s.size());
        System.assertEquals('22', product2s[0].StorageStatus__c);
        }

        //SFDC停止预警  lt  20210922 add start
        @isTest 
	static void CalAverageMonthSales(){

        Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='SP',
                Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n05',
                ProductCode_Ext__c='pc05',Manual_Entry__c=false,
                StorageStatus__c = '',StorageStatusNo__c = 22,
                WhiteSpace__c = false,
                M_BC_Stop_manufacure__c =Date.today());
        insert pro5;

        Product2 pro6 = new Product2();
        pro6.Name = 'name06';
        pro6.IsActive=true;
        pro6.Family='SP';
        pro6.Fixture_Model_No__c='n05';
        pro6.Serial_Lot_No__c='S/N tracing';
        pro6.Fixture_Model_No_T__c = 'n05';
        pro6.ProductCode_Ext__c='pc05';
        pro6.Manual_Entry__c=false;
        pro6.StorageStatus__c = '';
        pro6.StorageStatusNo__c = 22;
        pro6.WhiteSpace__c = false;
        //pro6.M_BC_Stop_manufacure__c = Date.today();
        pro6.SFDA_Status__c = '有効';
        pro6.Correspond_Code__c = pro5.Id;
        pro6.M_BC_Stop_manufacure__c =Date.today().addDays(1);
        insert pro6;

        ProductMonthlySales__c ms = new ProductMonthlySales__c();
        ms.MonthSales__c = 6;
        ms.CurrentDate__c = Date.today();
        ms.ProductM__c = pro6.Id;
        ms.Product2Model__c = 'test123';
        insert ms;

        ProductMonthlySales__c ms1 = new ProductMonthlySales__c();
        ms1.MonthSales__c = 6;
        ms1.CurrentDate__c = Date.today();
        ms1.ProductM__c = pro6.Id;
        ms1.Product2Model__c = 'test123';
        insert ms1;

        ProductMonthlySales__c ms2 = new ProductMonthlySales__c();
        ms2.MonthSales__c = 6;
        ms2.CurrentDate__c = Date.today();
        ms2.ProductM__c = pro6.Id;
        ms2.Product2Model__c = 'test123';
        insert ms2;

        ProductMonthlySales__c ms3 = new ProductMonthlySales__c();
        ms3.MonthSales__c = 6;
        ms3.CurrentDate__c = Date.today();
        ms3.ProductM__c = pro6.Id;
        ms3.Product2Model__c = 'test123';
        insert ms3;

        ProductMonthlySales__c ms4 = new ProductMonthlySales__c();
        ms4.MonthSales__c = 6;
        ms4.CurrentDate__c = Date.today();
        ms4.ProductM__c = pro6.Id;
        ms4.Product2Model__c = 'test123';
        insert ms4;

        ProductMonthlySales__c ms5 = new ProductMonthlySales__c();
        ms5.MonthSales__c = 6;
        ms5.CurrentDate__c = Date.today();
        ms5.ProductM__c = pro6.Id;
        ms5.Product2Model__c = 'test123';
        insert ms5;

        ProductMonthlySales__c ms6 = new ProductMonthlySales__c();
        ms6.MonthSales__c = 6;
        ms6.CurrentDate__c = Date.today();
        ms6.ProductM__c = pro6.Id;
        ms6.Product2Model__c = 'test123';
        insert ms6;

        ProductMonthlySales__c ms7 = new ProductMonthlySales__c();
        ms7.MonthSales__c = 6;
        ms7.CurrentDate__c = Date.today();
        ms7.ProductM__c = pro6.Id;
        ms7.Product2Model__c = 'test123';
        insert ms7;

        ProductMonthlySales__c ms8 = new ProductMonthlySales__c();
        ms8.MonthSales__c = 6;
        ms8.CurrentDate__c = Date.today();
        ms8.ProductM__c = pro6.Id;
        ms8.Product2Model__c = 'test123';
        insert ms8;

        ProductMonthlySales__c ms9 = new ProductMonthlySales__c();
        ms9.MonthSales__c = 6;
        ms9.CurrentDate__c = Date.today();
        ms9.ProductM__c = pro6.Id;
        ms9.Product2Model__c = 'test123';
        insert ms9;

        ProductMonthlySales__c msa = new ProductMonthlySales__c();
        msa.MonthSales__c = 6;
        msa.CurrentDate__c = Date.today();
        msa.ProductM__c = pro6.Id;
        msa.Product2Model__c = 'test123';
        insert msa;

        ProductMonthlySales__c msb = new ProductMonthlySales__c();
        msb.MonthSales__c = 6;
        msb.CurrentDate__c = Date.today();
        msb.ProductM__c = pro6.Id;
        msb.Product2Model__c = 'test123';
        insert msb;

        ProductMonthlySales__c msnew = new ProductMonthlySales__c();
        msnew.MonthSales__c = 6;
        msnew.CurrentDate__c = Date.today();
        msnew.ProductM__c = pro5.Id;
        msnew.Product2Model__c = 'test123';
        insert msnew;

        ProductMonthlySales__c msnew1 = new ProductMonthlySales__c();
        msnew1.MonthSales__c = 6;
        msnew1.CurrentDate__c = Date.today();
        msnew1.ProductM__c = pro5.Id;
        msnew1.Product2Model__c = 'test123';
        insert msnew1;

        ProductMonthlySales__c msnew2 = new ProductMonthlySales__c();
        msnew2.MonthSales__c = 6;
        msnew2.CurrentDate__c = Date.today();
        msnew2.ProductM__c = pro5.Id;
        msnew2.Product2Model__c = 'test123';
        insert msnew2;

        ProductMonthlySales__c msnew3 = new ProductMonthlySales__c();
        msnew3.MonthSales__c = 6;
        msnew3.CurrentDate__c = Date.today();
        msnew3.ProductM__c = pro5.Id;
        msnew3.Product2Model__c = 'test123';
        insert msnew3;

        ProductMonthlySales__c msnew4 = new ProductMonthlySales__c();
        msnew4.MonthSales__c = 6;
        msnew4.CurrentDate__c = Date.today();
        msnew4.ProductM__c = pro5.Id;
        msnew4.Product2Model__c = 'test123';
        insert msnew4;

        ProductMonthlySales__c msnew5 = new ProductMonthlySales__c();
        msnew5.MonthSales__c = 6;
        msnew5.CurrentDate__c = Date.today();
        msnew5.ProductM__c = pro5.Id;
        msnew5.Product2Model__c = 'test123';
        insert msnew5;

        ProductMonthlySales__c msnew6 = new ProductMonthlySales__c();
        msnew6.MonthSales__c = 6;
        msnew6.CurrentDate__c = Date.today();
        msnew6.ProductM__c = pro5.Id;
        msnew6.Product2Model__c = 'test123';
        insert msnew6;

        ProductMonthlySales__c msnew7 = new ProductMonthlySales__c();
        msnew7.MonthSales__c = 6;
        msnew7.CurrentDate__c = Date.today();
        msnew7.ProductM__c = pro5.Id;
        msnew7.Product2Model__c = 'test123';
        insert msnew7;

        ProductMonthlySales__c msnew8 = new ProductMonthlySales__c();
        msnew8.MonthSales__c = 6;
        msnew8.CurrentDate__c = Date.today();
        msnew8.ProductM__c = pro5.Id;
        msnew8.Product2Model__c = 'test123';
        insert msnew8;

        ProductMonthlySales__c msnew9 = new ProductMonthlySales__c();
        msnew9.MonthSales__c = 6;
        msnew9.CurrentDate__c = Date.today();
        msnew9.ProductM__c = pro5.Id;
        msnew9.Product2Model__c = 'test123';
        insert msnew9;

        ProductMonthlySales__c msnew10 = new ProductMonthlySales__c();
        msnew10.MonthSales__c = 6;
        msnew10.CurrentDate__c = Date.today();
        msnew10.ProductM__c = pro5.Id;
        msnew10.Product2Model__c = 'test123';
        insert msnew10;

        ProductMonthlySales__c msnew11 = new ProductMonthlySales__c();
        msnew11.MonthSales__c = 6;
        msnew11.CurrentDate__c = Date.today();
        msnew11.ProductM__c = pro5.Id;
        msnew11.Product2Model__c = 'test123';
        insert msnew11;

        pro6.StorageStatusNo__c = 20;
        update pro6;

        }

        @isTest 
	static void CalAverageMonthSales2(){

        Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='SP',
                Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n05',
                ProductCode_Ext__c='pc05',Manual_Entry__c=false,
                StorageStatus__c = '',StorageStatusNo__c = 22,
                WhiteSpace__c = false,
                M_BC_Stop_manufacure__c = Date.today());
        insert pro5;

        Product2 pro6 = new Product2();
        pro6.Name = 'name06';
        pro6.IsActive=true;
        pro6.Family='SP';
        pro6.Fixture_Model_No__c='n05';
        pro6.Serial_Lot_No__c='S/N tracing';
        pro6.Fixture_Model_No_T__c = 'n05';
        pro6.ProductCode_Ext__c='pc05';
        pro6.Manual_Entry__c=false;
        pro6.StorageStatus__c = '';
        pro6.StorageStatusNo__c = 22;
        pro6.WhiteSpace__c = false;
        pro6.M_BC_Stop_manufacure__c = Date.today().addDays(1);
        pro6.SFDA_Status__c = '有効';
        pro6.Correspond_Code__c = pro5.Id;
        insert pro6;

        ProductMonthlySales__c ms = new ProductMonthlySales__c();
        ms.MonthSales__c = 6;
        ms.CurrentDate__c = Date.today();
        ms.ProductM__c = pro6.Id;
        ms.Product2Model__c = 'test123';
        insert ms;

        ProductMonthlySales__c msnew = new ProductMonthlySales__c();
        msnew.MonthSales__c = 6;
        msnew.CurrentDate__c = Date.today();
        msnew.ProductM__c = pro5.Id;
        msnew.Product2Model__c = 'test123';
        insert msnew;

        pro6.StorageStatusNo__c = 20;
        update pro6;

        }

        @isTest 
	static void CalAverageMonthSales3(){

        Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='SP',
                Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n05',
                ProductCode_Ext__c='pc05',Manual_Entry__c=false,
                StorageStatus__c = '',StorageStatusNo__c = 22,
                WhiteSpace__c = false,
                M_BC_Stop_manufacure__c =Date.today());
        insert pro5;

        Product2 pro6 = new Product2();
        pro6.Name = 'name06';
        pro6.IsActive=true;
        pro6.Family='SP';
        pro6.Fixture_Model_No__c='n05';
        pro6.Serial_Lot_No__c='S/N tracing';
        pro6.Fixture_Model_No_T__c = 'n05';
        pro6.ProductCode_Ext__c='pc05';
        pro6.Manual_Entry__c=false;
        pro6.StorageStatus__c = '';
        pro6.StorageStatusNo__c = 22;
        pro6.WhiteSpace__c = false;
        //pro6.M_BC_Stop_manufacure__c = Date.today();
        pro6.SFDA_Status__c = '有効';
        pro6.Correspond_Code__c = pro5.Id;
        pro6.M_BC_Stop_manufacure__c =Date.today().addDays(1);
        insert pro6;

        ProductMonthlySales__c ms = new ProductMonthlySales__c();
        ms.MonthSales__c = 6;
        ms.CurrentDate__c = Date.today();
        ms.ProductM__c = pro6.Id;
        ms.Product2Model__c = 'test123';
        insert ms;

        ProductMonthlySales__c ms1 = new ProductMonthlySales__c();
        ms1.MonthSales__c = 6;
        ms1.CurrentDate__c = Date.today();
        ms1.ProductM__c = pro6.Id;
        ms1.Product2Model__c = 'test123';
        insert ms1;

        ProductMonthlySales__c ms2 = new ProductMonthlySales__c();
        ms2.MonthSales__c = 6;
        ms2.CurrentDate__c = Date.today();
        ms2.ProductM__c = pro6.Id;
        ms2.Product2Model__c = 'test123';
        insert ms2;

        ProductMonthlySales__c ms3 = new ProductMonthlySales__c();
        ms3.MonthSales__c = 6;
        ms3.CurrentDate__c = Date.today();
        ms3.ProductM__c = pro6.Id;
        ms3.Product2Model__c = 'test123';
        insert ms3;

        ProductMonthlySales__c ms4 = new ProductMonthlySales__c();
        ms4.MonthSales__c = 6;
        ms4.CurrentDate__c = Date.today();
        ms4.ProductM__c = pro6.Id;
        ms4.Product2Model__c = 'test123';
        insert ms4;

        ProductMonthlySales__c ms5 = new ProductMonthlySales__c();
        ms5.MonthSales__c = 6;
        ms5.CurrentDate__c = Date.today();
        ms5.ProductM__c = pro6.Id;
        ms5.Product2Model__c = 'test123';
        insert ms5;

        ProductMonthlySales__c ms6 = new ProductMonthlySales__c();
        ms6.MonthSales__c = 6;
        ms6.CurrentDate__c = Date.today();
        ms6.ProductM__c = pro6.Id;
        ms6.Product2Model__c = 'test123';
        insert ms6;

        ProductMonthlySales__c ms7 = new ProductMonthlySales__c();
        ms7.MonthSales__c = 6;
        ms7.CurrentDate__c = Date.today();
        ms7.ProductM__c = pro6.Id;
        ms7.Product2Model__c = 'test123';
        insert ms7;

        ProductMonthlySales__c ms8 = new ProductMonthlySales__c();
        ms8.MonthSales__c = 6;
        ms8.CurrentDate__c = Date.today();
        ms8.ProductM__c = pro6.Id;
        ms8.Product2Model__c = 'test123';
        insert ms8;

        ProductMonthlySales__c ms9 = new ProductMonthlySales__c();
        ms9.MonthSales__c = 6;
        ms9.CurrentDate__c = Date.today();
        ms9.ProductM__c = pro6.Id;
        ms9.Product2Model__c = 'test123';
        insert ms9;

        ProductMonthlySales__c msa = new ProductMonthlySales__c();
        msa.MonthSales__c = 6;
        msa.CurrentDate__c = Date.today();
        msa.ProductM__c = pro6.Id;
        msa.Product2Model__c = 'test123';
        insert msa;

        ProductMonthlySales__c msb = new ProductMonthlySales__c();
        msb.MonthSales__c = 6;
        msb.CurrentDate__c = Date.today();
        msb.ProductM__c = pro6.Id;
        msb.Product2Model__c = 'test123';
        insert msb;

        ProductMonthlySales__c msnew = new ProductMonthlySales__c();
        msnew.MonthSales__c = 6;
        msnew.CurrentDate__c = Date.today();
        msnew.ProductM__c = pro5.Id;
        msnew.Product2Model__c = 'test123';
        insert msnew;

        pro6.StorageStatusNo__c = 20;
        update pro6;

        }

	//SFDC停止预警  lt  20210922 add end
	
}