GWY
2022-04-27 12b7399736e90d33bfe0c2d29917d6f075246e00
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@isTest
private class loanerChangeRecordTriggerHandlerTest {
 
    static Product2 prd1;
    static Product2 prd2;
    static Account acc;
    static Account dealer;
    static Contact core;
    static User testUser;
    static Asset asset;
    static Asset assetC1;
    static Asset assetC2;
 static void setupTestData() {   
     List<RecordType> dealerIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        if (dealerIE.size() == 0) {
            return;
        }
        List<RecordType> olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany'];
        if (olyCompany.size() == 0) {
            return;
        }
 
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        List<RecordType> loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理'];
        if (loa_number.size() == 0) {
            return;
        }
 
     //代理商用户
        List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        Profile prof = [select Id from Profile where Name ='SSBG DEALER IE'];
        dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'IE';
        dealer.PostCode__c='000000';
        insert dealer;
        core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
        insert testUser;
 
        //样机客户
        acc = new Account();
        acc.Name = 'test dealer';
        acc.RecordTypeId = olyCompany[0].Id;
        acc.ProductSegment__c = 'IE';
        acc.PostCode__c='000000';
        insert acc;
 
    // 产品
        prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'testSBG001';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;
 
        prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'testSBG002';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        insert new Product2[] {prd1, prd2};
 
        // 保有设备 (个体管理)
        assetC1 = new Asset();
        assetC1.RecordTypeId = loa_individual[0].Id;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = acc.Id;
        assetC1.Product2Id = prd1.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '在库';
        assetC1.Equipment_Type__c = 'IE';
        assetC1.loaner_place__c = '北京酒仙桥';
        assetC1.Remarks2__c = 'assetC1';
        
        // 保有设备 (个体管理)
        assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd2.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        insert new Asset[] {assetC2,assetC1};
        
 }       
     @isTest static void test_method_one() { 
     
    setupTestData();
 
    List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
   
     // Implement test code
    LoanerChangeRecord__c cr1 = new LoanerChangeRecord__c();
        cr1.Loaner__c = assetC1.Id;
        cr1.LoanerStatus__c = '在库';
        cr1.ChangeToStatus__c = '冻结';
        cr1.ChangeReason__c = 'test1';
        insert cr1;
     }  
        
        
        
    }