liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@isTest
private class FixtureSetDetailDailyUpdateBatchTest {
    static Product2 pro1;
    static Product2 pro2;
    static Fixture_Set_Detail__c fsd1;
    static void setupData(){
        pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='SB-MODEL-01',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'SB-MODEL-01', Asset_Model_No__c = 'Pro01',
                ProductCode_Ext__c='SB-PRO-CODE-01',Manual_Entry__c=false,
                ProductCode = 'SB-PRO-CODE-01');
        pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
                Fixture_Model_No__c='SB-MODEL-02',Serial_Lot_No__c='Lot tracing',
                Fixture_Model_No_T__c = 'SB-MODEL-02', Asset_Model_No__c = 'Pro02',
                ProductCode_Ext__c='SB-PRO-CODE-02',Manual_Entry__c=false,
                ProductCode = 'SB-PRO-CODE-02');
        insert new Product2[] {pro1, pro2};
 
        Fixture_Set__c fs = new Fixture_Set__c();
        fs.Name = 'SB-FS-01';
        fs.Fixture_Set_Body_Model_No__c = 'SB-FS-MODEL-01';
        fs.Loaner_name__c = 'SB-FS-1';
        insert fs ;
 
        fsd1 = new Fixture_Set_Detail__c();
        fsd1.Name = 'SB-FSD-1';
        fsd1.Name_CHN_Created__c = 'SB-中文FSD-1';
        fsd1.Product2__c = pro1.Id;
        fsd1.Fixture_Set__c = fs.Id;
        fsd1.UniqueKey__c = fs.Id + ':' + pro1.Id;
        insert fsd1;
    }
    // 配套明细状态true->false
    static testMethod void testMethod1() {
        setupData();
        List<Product2> proList = [SELECT SFDA_Status__c FROM Product2];
        System.assertEquals('停止',proList[0].SFDA_Status__c);
        System.assertEquals('停止',proList[1].SFDA_Status__c);
        Fixture_Set_Detail__c fsd = [SELECT Product_Status_Flag__c FROM Fixture_Set_Detail__c];
        System.assertEquals(true, fsd.Product_Status_Flag__c);
 
        Test.startTest();
        Database.executeBatch(new FixtureSetDetailDailyUpdateBatch(), 100);
        Test.stopTest();
 
        fsd = [SELECT Product_Status_Flag__c FROM Fixture_Set_Detail__c];
        System.assertEquals(true, fsd.Product_Status_Flag__c);
    }
    // 配套明细状态false->true
    static testMethod void testMethod2() {
        setupData();
        pro1.SFDA_Status__c = '有效';
        fsd1.Product_Status_Flag__c = false;
        update pro1;
        update fsd1;
        List<Product2> proList = [SELECT SFDA_Status__c FROM Product2];
        System.assertEquals('有效',proList[0].SFDA_Status__c);
        System.assertEquals('停止',proList[1].SFDA_Status__c);
        Fixture_Set_Detail__c fsd = [SELECT Product_Status_Flag__c FROM Fixture_Set_Detail__c];
        System.assertEquals(false, fsd.Product_Status_Flag__c);
 
        Test.startTest();
        Database.executeBatch(new FixtureSetDetailDailyUpdateBatch(), 100);
        Test.stopTest();
 
        fsd = [SELECT Product_Status_Flag__c FROM Fixture_Set_Detail__c];
        System.assertEquals(true, fsd.Product_Status_Flag__c);
    }
    static testMethod void testMethod3() {
        FixtureSetDetailDailyUpdateBatch b = new FixtureSetDetailDailyUpdateBatch();
        b.errorList.add('Test');
        Database.executeBatch(b);
    }
}