@isTest
private class UpdateTotalCostPriceSetTextBatchTest {
    static testMethod void testMethod1() {
         List<RecordType> rectBS = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
        Account accBS = new Account(
            Name = '*',
            RecordTypeId = rectBS[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer BS',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accBS;

        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accBS.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';

        insert con;

        Id pricebookId = Test.getStandardPricebookId();

        Pricebook2 pricebook = new Pricebook2(
            Name = 'BS',
            ProductSegment__c = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;

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

        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true
        );
        insert standardPrice1;

        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        insert entry1;

        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accBS.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct',
            TradeType__c = 'Taxation',
            Machine_Parts__c = 'Machine',
            InquiryResult__c = '112233'
        );
        insert opp;

        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accBS.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            IE_SP5_D__c = true,
            SpecialDeliveryAccount_D__c = accBS.Id,
            SpecialDeliveryContact2_D__c = con.Id
        );
        insert odr;

        OrderItem oi1 = new OrderItem(
            OrderId = odr.Id,
            PriceBookEntryId = entry1.Id,
            Quantity = 1,
            UnitPrice = 10
        );
        insert oi1;
        List<String> ids = new List<String>();
        ids.add(odr.Id);
        Database.executeBatch(new UpdateTotalCostPriceSetTextBatch(), 20);  
        Database.executeBatch(new UpdateTotalCostPriceSetTextBatch(ids), 20);	
        UpdateTotalCostPriceSetTextBatch.executeWebSide1(odr.Id);
    }
}