@isTest
private class RentalApplyEquipmentSetTriggerTest {
    
    static testMethod void myUnitTest() {
        // システム管理者
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;
        
        //备品借出申请
        Rental_Apply__c rentalApply = new Rental_Apply__c();
        rentalApply.OwnerId = user.Id;
        rentalApply.CurrencyIsoCode = 'CNY';
        rentalApply.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Yi_Chu_Ku_Zhi_Shi.ordinal());
        rentalApply.Asset_loaner_start_day__c = Date.today();
        rentalApply.Asset_loaner_closed_day__c = Date.today().addDays(10);
//bp2        rentalApply.Rental_End_Date__c = Date.today() + 30;
        rentalApply.applyUser__c = user.Id;
        rentalApply.direct_send__c = '直送';
        rentalApply.direct_shippment_address__c = 'test';
        rentalApply.Request_return_day__c = Date.today() + 30;
        insert rentalApply;
        
//bp2 TODO Fixture_Set__c
//bp2        //备品set
//        Equipment_Set__c equipmentSet1 = new Equipment_Set__c();
//        equipmentSet1.Name = '备品Set01';
//        equipmentSet1.CurrencyIsoCode = 'CNY';
//        insert equipmentSet1;
        
        //备品借出历史
        Rental_Apply_Equipment_Set__c rentalApplyEquipmentSet1 = new Rental_Apply_Equipment_Set__c();
        rentalApplyEquipmentSet1.Rental_Apply__c = rentalApply.Id;
//bp2        rentalApplyEquipmentSet1.Equipment_Set__c = equipmentSet1.Id;
        rentalApplyEquipmentSet1.CurrencyIsoCode = 'CNY';
//bp2   rentalApplyEquipmentSet1.Shipment_request_time__c = Datetime.now();
        rentalApplyEquipmentSet1.Shippment_loaner_time__c = Datetime.now();
        rentalApplyEquipmentSet1.applyUser__c = user.Id;
        insert rentalApplyEquipmentSet1;
        
        Rental_Apply_Equipment_Set__c raes1 = [select Id,SalesManager__c,BuchangApprovalManagerSales__c,JingliApprovalManager__c,
                                                      BuchangApprovalManager__c,ZongjianApprovalManager__c 
                                                 from Rental_Apply_Equipment_Set__c 
                                                where Id = :rentalApplyEquipmentSet1.Id];
        System.assertEquals(null, raes1.SalesManager__c);
        System.assertEquals(null, raes1.BuchangApprovalManagerSales__c);
        System.assertEquals(null, raes1.JingliApprovalManager__c);
        System.assertEquals(null, raes1.BuchangApprovalManager__c);
        System.assertEquals(null, raes1.ZongjianApprovalManager__c);
        
        rentalApplyEquipmentSet1.Extend_Status__c = '申请中';
        update rentalApplyEquipmentSet1;
        
        Rental_Apply_Equipment_Set__c raes2 = [select Id,SalesManager__c,BuchangApprovalManagerSales__c,JingliApprovalManager__c,
                                                      BuchangApprovalManager__c,ZongjianApprovalManager__c 
                                                 from Rental_Apply_Equipment_Set__c 
                                                where Id = :rentalApplyEquipmentSet1.Id];
        System.assertNotEquals(null, raes2.SalesManager__c);
        System.assertNotEquals(null, raes2.BuchangApprovalManagerSales__c);
        System.assertNotEquals(null, raes2.JingliApprovalManager__c);
        System.assertNotEquals(null, raes2.BuchangApprovalManager__c);
        System.assertNotEquals(null, raes2.ZongjianApprovalManager__c);
    }
}