Li Jun
2022-03-31 3ba0123db48f8bab81ddf0913e1b95280ef545e8
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@isTest
private class AgencyContactHandlerTest {
 
    public static Account account1 = new Account();
    public static Account account2 = new Account();
    public static Agency_Hospital_Link__c aHosLink = new Agency_Hospital_Link__c();
    public static Agency_Contact__c aContact = new Agency_Contact__c();
    static testMethod void testBeforeInsert() {
 
        // 取引先
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
 
        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
 
 
        List<Account> accTestList = [SELECT Id, Name FROM Account order by Name];
        System.debug('GYFaccTestList='+accTestList);
        System.assertEquals(10, accTestList.size());
        System.assertEquals('test1医院', accTestList[0].Name);
 
        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        insert aHosLink;
 
        //.客户人员データを作る
        List<Agency_Contact__c> aContactList = new List<Agency_Contact__c>();
        Agency_Contact__c aContact1 = new Agency_Contact__c();
        aContact1.Agency_Hospital__c = aHosLink.Id;
        aContact1.Type__c = '医生';
        aContact1.Name = 'testAgencyUser';
        aContactList.add(aContact1);
 
        Agency_Contact__c aContact2 = new Agency_Contact__c();
        aContact2.Agency_Hospital__c = aHosLink.Id;
        aContact2.Type__c = '护士';
        aContact2.Name = 'testAgencyUser';
        aContactList.add(aContact2);
        Test.startTest();
        insert aContactList;
        ////经销商医院名前を変更する
        //aContact.Name = 'testAgencyUser1'
        //update aContact;
 
        Agency_Contact__c clonedAC = aContact1.clone(false,true,false,false);
        clonedAC.Name = 'testAgencyUser2';
        clonedAC.Agency_ID__c = '000000000000000';
        clonedAC.Agency_Hospital__c  = null;
        insert clonedAC;
        Test.stopTest();
    }
    static testMethod void testBeforeUpdate() {
 
        // 取引先
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
 
        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
 
 
        List<Account> accTestList = [SELECT Id, Name FROM Account order by Name];
        System.debug('GYFaccTestList='+accTestList);
        System.assertEquals(10, accTestList.size());
        System.assertEquals('test1医院', accTestList[0].Name);
 
        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        insert aHosLink;
 
        //.客户人员データを作る
        aContact.Agency_Hospital__c = aHosLink.Id;
        aContact.Type__c = '医生';
        aContact.Name = 'testAgencyUser';
 
        Agency_Contact__c aContact2 = new Agency_Contact__c();
        aContact2.Agency_Hospital__c = aHosLink.Id;
        aContact2.Type__c = '医生';
        aContact2.Name = 'testAgencyUser1';
        insert aContact2;
 
        Test.startTest();
        try{
            insert aContact;
        }catch(Exception e){
            system.debug('Exception from insert contact:'+e.getMessage());
        }
        ////.客户人员名前を変更する
        aContact.Name = 'testAgencyUser1';
        try {
            update aContact;
        } catch (Exception e) {
 
        }
        
        Test.stopTest();
    }
 
    @isTest static void test_setAgency_Contact_Share_ToRole() {
        MergeAgencyActivityBatchTest.makeNormalData(true);
 
        // assert
        List<Agency_Contact__c> tList = [SELECT Name, Agency_Hospital__r.Agency__c
                FROM Agency_Contact__c ORDER BY Id LIMIT 2];
        System.assertEquals(2, tList.size());
        System.assertEquals(MergeAgencyActivityBatchTest.agency1.Id, tList[0].Agency_Hospital__r.Agency__c);
        System.assertEquals(MergeAgencyActivityBatchTest.agency1.Id, tList[1].Agency_Hospital__r.Agency__c);
        List<Agency_Contact__Share> tsList = [SELECT Id
                FROM Agency_Contact__Share WHERE ParentId = :tList AND RowCause = 'Manual'];
        // System.assertEquals(2, tsList.size());
 
        Test.startTest();
        Delete tList[0];
        Test.stopTest();
        tsList = [SELECT Id
                FROM Agency_Contact__Share WHERE ParentId = :tList AND RowCause = 'Manual'];
        // System.assertEquals(1, tsList.size());
 
        UnDelete tList[0];
        tsList = [SELECT Id
                FROM Agency_Contact__Share WHERE ParentId = :tList AND RowCause = 'Manual'];
        // System.assertEquals(2, tsList.size());
    }
}