buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
@isTest
private class AssetNumberChangeControllerTest {
    @isTest static void test_method_one() {
        List<RecordType> loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理'];
        if (loa_number.size() == 0) {
            return;
        }
        List<RecordType> olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany'];
        if (olyCompany.size() == 0) {
            return;
        }
        //样机客户
        Account acc = new Account();
        acc.Name = 'test dealer';
        acc.RecordTypeId = olyCompany[0].Id;
        acc.ProductSegment__c = 'IE';
        acc.PostCode__c='000000';
        insert acc;
 
        // 产品
        Product2 prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'testSBG001';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;
 
        Product2 prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'testSBG002';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        insert new Product2[] {prd1, prd2};
 
        // 保有设备 (数量管理)
        Asset asset = new Asset();
        asset.RecordTypeId = loa_number[0].Id;
        asset.SerialNumber = 'asset';
        asset.Name = 'asset';
        asset.AccountId = acc.Id;
        asset.Product2Id = prd2.Id;
        asset.Quantity = 1;
        asset.Status = '在库';
        asset.Equipment_Type__c = 'IE';
        asset.loaner_place__c = '广州办';
        asset.total_number__c = 20;
        asset.Remarks2__c = 'asset';
 
        insert asset;
 
        PageReference page = new PageReference('/apex/AssetNumberChange?id=' + asset.Id);
        page.setRedirect(true);
        System.Test.setCurrentPage(page);
        AssetNumberChangeController loanerApplyCon = new AssetNumberChangeController();
        loanerApplyCon.init();
        System.assertEquals('asset', loanerApplyCon.ast.Name);
        loanerApplyCon.saveBtn();
        loanerApplyCon.lch.change_content__c= '追加';
        loanerApplyCon.saveBtn();
        loanerApplyCon.lch.change_number__c= 30;
        loanerApplyCon.saveBtn();
        asset = [select Id,total_number__c from asset where Id = :asset.Id];
        System.assertEquals(50, asset.total_number__c);
 
        loanerApplyCon.cancelBtn();
    }
}