@isTest
private class ConsumEquipmentSetShipmentControllerTest {

    // static testMethod void testCoverUp() {
    //    ConsumEquipmentSetShipmentController.test();
    //}//System.LimitException: Too many SOQL queries: 101  

   
    // 造出出库指示完成数据
    @testSetup static void setupTestData(){
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
        factory.approve();
        factory.defaultAssign();
        factory.shippmentRequest();
    }
    static testMethod void testSave() {
        Consum_Apply__c ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
        Consum_Apply_Equipment_Set__c caes = [SELECT Id, Consum_Apply__c FROM Consum_Apply_Equipment_Set__c LIMIT 1];
        System.assertEquals(null, ca.Shipment_Slip_tmp__c);

        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Id
                          , Shippment_loaner_time__c
                          , DeliverySlip__c
                          , RAESD_Status__c
                       FROM Consum_Apply_Equipment_Set_Detail__c
                       WHERE Consum_Apply__c=:ca.Id
                ];
        System.assertEquals(null, caesdList[0].Shippment_loaner_time__c);
        System.assertEquals(null, caesdList[0].DeliverySlip__c);
        System.assertEquals('已出库指示', caesdList[0].RAESD_Status__c);

        PageReference ref = new PageReference('/apex/ConsumEquipmentSetShipment?Id=' + caes.Id);
        Test.setCurrentPage(ref);
        ConsumEquipmentSetShipmentController controller = new ConsumEquipmentSetShipmentController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.init();
        controller.myComponentController.init();
        controller.searchOpp();
        Test.startTest();
        controller.slip.Name = '运输单号';
        controller.slip.DeliveryType__c = '发货';
        controller.slip.Distributor_method__c = '陆运';
        controller.slip.DeliveryCompany__c = 'Fedex';
        controller.slip.Wh_Staff__c = Userinfo.getUserId();
        controller.slip.Combine_Pack__c = '123';
        controller.save();
        Test.stopTest();
        ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
        System.assertNotEquals(null, ca.Shipment_Slip_tmp__c);
    }

    static testMethod void testSend() {
        Consum_Apply__c ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
        Consum_Apply_Equipment_Set__c caes = [SELECT Id FROM Consum_Apply_Equipment_Set__c LIMIT 1];
        System.assertEquals(null, ca.Shipment_Slip_tmp__c);
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Id
                          , Shippment_loaner_time__c
                          , DeliverySlip__c
                          , RAESD_Status__c
                       FROM Consum_Apply_Equipment_Set_Detail__c
                       WHERE Consum_Apply__c=:ca.Id
                ];
        System.assertEquals(null, caesdList[0].Shippment_loaner_time__c);
        System.assertEquals(null, caesdList[0].DeliverySlip__c);
        System.assertEquals('已出库指示', caesdList[0].RAESD_Status__c);

        PageReference ref = new PageReference('/apex/ConsumEquipmentSetShipment?Id=' + caes.Id);
        Test.setCurrentPage(ref);
        ConsumEquipmentSetShipmentController controller = new ConsumEquipmentSetShipmentController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.init();
        controller.myComponentController.init();
        controller.searchOpp();

        Test.startTest();
        controller.cancel();
        controller.searchSlip();
        controller.slip.Name = '运输单号';
        controller.slip.DeliveryType__c = '发货';
        controller.slip.Distributor_method__c = '陆运';
        controller.slip.DeliveryCompany__c = 'Fedex';
        controller.slip.Wh_Staff__c = Userinfo.getUserId();
        controller.slip.Combine_Pack__c = '123';
        controller.viewList[0].check = true;
        Consum_Apply_Equipment_Set_Detail__c caesd = (Consum_Apply_Equipment_Set_Detail__c)controller.viewList[0].sobj;
        caesd.Inspection_Cnt_Jia__c = 1;
        controller.send();
        Test.stopTest();

        caesdList = [SELECT Id
                          , Shippment_loaner_time__c
                          , DeliverySlip__c
                          , RAESD_Status__c
                       FROM Consum_Apply_Equipment_Set_Detail__c
                       WHERE Consum_Apply__c=:ca.Id
                ];
        System.assertNotEquals(null, caesdList[0].Shippment_loaner_time__c);
        System.assertNotEquals(null, caesdList[0].DeliverySlip__c);
        System.assertEquals('已出库', caesdList[0].RAESD_Status__c);
        FixtureDeliverySlip__c slip = [SELECT Name
                                             , DeliveryType__c
                                             , Distributor_method__c
                                             , DeliveryCompany__c
                                             , Wh_Staff__c
                                             , Combine_Pack__c
                                             FROM FixtureDeliverySlip__c
                                             WHERE Id=:caesdList[0].DeliverySlip__c
                                        ];
        System.assertEquals('运输单号', slip.Name);
        System.assertEquals('发货', slip.DeliveryType__c);
        System.assertEquals('陆运', slip.Distributor_method__c);
        System.assertEquals('Fedex', slip.DeliveryCompany__c);
        System.assertEquals(Userinfo.getUserId(), slip.Wh_Staff__c);
        System.assertEquals('123', slip.Combine_Pack__c);




    }
}