@isTest
private class SBG007TriggerHandlerTest
{
//	static testMethod void itShould(){
//		List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
//        Account accIE = new Account(
//        	Name = '*',
//        	RecordTypeId = rectIE[0].Id,
//        	OwnerId = UserInfo.getUserId(),
//        	DivisionName__c='Customer IE',
//        	FacilityName__c='abc',
//            PostCode__c = '123456'
//        );
//        insert accIE;
//PriceBook2 pricebook =new PriceBook2(
//        	Name = 'IE',
//            ProductSegment__c = 'IE',
//            TradeType__c = 'Taxation',
//            SalesChannel__c = 'direct',
//            MachineParts__c = 'Machine'
//        );
//        insert pricebook;

//        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
//        Opportunity opp = new Opportunity(
//            Name = 'test opp',
//            the_Upload_of_quotation_number__c = 'test1',
//            AccountId = accIE.Id,
//            RecordTypeId = rectOpp[0].Id,
//            OwnerId = UserInfo.getUserId(),
//            StageName = 'Prospect Created',
//            CancelReason__c = 'Inquiry repeat',
//            Cancel_reason_D__c = 'Inquiry repeat',
//            CurrencyIsoCode = 'CNY',
//            ProductSegment__c = 'IE',
//            CloseDate = Date.today(),
//            NewInquiryDate__c = Date.today().addDays(-2),
//            ExpectedOrderDate__c = Date.today().addDays(2),
//            TradeType__c = 'Taxation',
//            SalesChannel__c = 'direct',
//            Machine_Parts__c = 'Machine'
//        );
//        insert opp;                
//         List<OpportunityLineItem> oppLiList = [select Id, Quantity, PricebookEntry.ProductCode, OpportunityId
//                                           from OpportunityLineItem where Opportunity.Id = :opp.Id ];
//        OpportunityLineItem oppLineItem = new OpportunityLineItem(
            
//            Quantity = 1,
//            //PricebookEntry.ProductCode='11',
//            OpportunityId= opp.Id
//        );
        
        
//        opp.the_Upload_of_quotation_number__c = 'test2';
//        upsert opp;
        

        
        

//        // SBG007より、送信しないこと
//           System.assertEquals('', SBG007TriggerHandler.debug_msg);

//	}

    static testMethod void itShould2(){
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c = '123456'
        );

        insert accIE;
        //PriceBook2 pricebook =new PriceBook2(
        //    Name = 'IE',
        //    ProductSegment__c = 'IE',
        //    TradeType__c = 'Taxation',
        //    SalesChannel__c = 'direct',
        //    MachineParts__c = 'Machine'
        //);
        //insert pricebook;

        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            the_Upload_of_quotation_number__c = 'test1',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;

         Quote quo = new Quote(
            //Name = 'quo',
            //OpportunityId = opp.Id,
            //SetName1__c = 'setname01',
            //SetQty1__c = 1,
            //Pricebook2Id = pricebook.Id
            Name = 'quo',
            OpportunityId = opp.Id,
            Pricebook2Id = pricebook.Id,
            SetName1__c = 'setname1',
            SetQty1__c = 1,
            SetName2__c = 'setname2',
            SetQty2__c = 2,
            Custom_Price_Total_Text__c = 1000
            //IsSyncing = true
        );
        insert quo;

        opp.SyncedQuoteId = quo.Id;
        update opp;

        List<productSet__c>  insertproductSets = new  List<productSet__c>();
        productSet__c proSet1 = new productSet__c();
        proSet1.Code__c = 'IXP-7P2';
        proSet1.Name = 'IXP-7P2';
        proSet1.IsValid__c = true;
        proSet1.Name = 'IXP-7P2';
        insertproductSets.add(proSet1);
        productSet__c proSet2 = new productSet__c();
        proSet2.Code__c = 'IXP-7P1SC';
        proSet2.Name = 'IXP-7P1SC';
        proSet2.IsValid__c = true;
        proSet2.Name = 'IXP-7P1SC';
        insertproductSets.add(proSet2);
        productSet__c proSet3 = new productSet__c();
        proSet3.Code__c = 'IXSP-T7LED';
        proSet3.Name = 'IXSP-T7LED';
        proSet3.IsValid__c = true;
        proSet3.Name = 'IXSP-T7LED';
        insertproductSets.add(proSet3);


        insert insertproductSets;

        Product2 product3 = new Product2();
        product3.Name = 'product3';
        product3.ProductCode = 'product3';
        product3.Product_ECCode__c = 'product3';
        product3.IsActive = true;

        insert product3;

        PricebookEntry entry1 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product3.Id,
            UnitPrice = 0,
            IsActive = true,
            UseStandardPrice = false
            //CurrencyIsoCode = 'CNY'
        );

        DecideQuoteProductSet__c dqps = new DecideQuoteProductSet__c();

        dqps.DecideProductSet__c = proSet1.Id ;
        dqps.DecideProductSetCount__c = 4;
        dqps.DecideOpportunity__c = opp.Id;
        dqps.DecideQuote__c = quo.Id;

        insert dqps;
                
         List<OpportunityLineItem> oppLiList = [select Id, Quantity, PricebookEntry.ProductCode, OpportunityId
                                           from OpportunityLineItem where Opportunity.Id = :opp.Id ];
        //OpportunityLineItem oppLineItem = new OpportunityLineItem(
            
        //    Quantity = 1,
        //    //PricebookEntry.ProductCode='11',
        //    OpportunityId= opp.Id,
        //    PricebookEntryId = entry1.Id,
        //     UnitPrice = 10
        //     //,
        //     //PricebookEntryId = entry1.Id,
        //);
        //OpportunityLineItem oppLineItem1 = new OpportunityLineItem(
            
        //    Quantity = 1,
        //    //PricebookEntry.ProductCode='11',
        //    OpportunityId= opp.Id,
        //    OLISingleProduct__c = true,
        //    PricebookEntryId = entry1.Id,
        //    UnitPrice = 10
        //);
        //insert new OpportunityLineItem[] {oppLineItem,oppLineItem1};
        

        OpportunityLineItem oli1 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            //PricebookEntryId = entry1.Id,
            Quantity = 10,
            UnitPrice = 10,
            Product2Id = product3.Id 
        );
        OpportunityLineItem oli2 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            //PricebookEntryId = entry1.Id,
            Quantity = 20,
            UnitPrice = 20,
            Product2Id = product3.Id 
        );
        //insert new OpportunityLineItem[] {oli1, oli2};
        opp.the_Upload_of_quotation_number__c = 'test2';
        upsert opp;
        

        
        

        // SBG007より、送信しないこと
           System.assertEquals('', SBG007TriggerHandler.debug_msg);

    }
}