高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@isTest
public class XinEventC2EventTriggerTest {
    
    //before insert, before update
    public static testMethod void myUnitTest() {
        Date now = Date.today();
        
        Daily_Report__c dr1 = new Daily_Report__c(
            Reported_Date__c = Date.today(),
            Status__c = '作成中',
            Reporter__c = Userinfo.getUserId()
        );
        insert dr1;
        
        Event__c ec1 = new Event__c(
            Daily_Report__c = dr1.Id,
            StartDateTime__c = Datetime.newInstance(now.year(), now.month(), now.day(), 10, 0, 0),
            EndDateTime__c = Datetime.newInstance(now.year(), now.month(), now.day(), 11, 0, 0),
            SyncCreatedDate__c = now.adddays(-1),
            ActivityDate__c = now,
            Subject__c = 'event1'
        );
        insert ec1;
        
        List<Event__c> eventList1 = [select id,IsScheduled__c,IsScheduled_StartDateTime__c,IsScheduled_EndDateTime__c,IsScheduled_Location__c,IsScheduled_Subject__c from Event__c where id = :ec1.Id];
        System.assertEquals(true, eventList1[0].IsScheduled__c);
        System.assertEquals(Datetime.newInstance(now.year(), now.month(), now.day(), 10, 0, 0), eventList1[0].IsScheduled_StartDateTime__c);
        System.assertEquals(Datetime.newInstance(now.year(), now.month(), now.day(), 11, 0, 0), eventList1[0].IsScheduled_EndDateTime__c);
        System.assertEquals('event1', eventList1[0].IsScheduled_Subject__c);
        
        ec1.IsScheduled__c = false;
        update ec1;
        
        List<Event__c> eventList2 = [select id,IsScheduled__c,IsScheduled_StartDateTime__c,IsScheduled_EndDateTime__c,IsScheduled_Location__c,IsScheduled_Subject__c from Event__c where id = :ec1.Id];
        System.assertEquals(null, eventList2[0].IsScheduled_StartDateTime__c);
        System.assertEquals(null, eventList2[0].IsScheduled_EndDateTime__c);
        System.assertEquals(null, eventList2[0].IsScheduled_Subject__c);
    }
    
    //after delete, after insert, after update
    public static testMethod void myUnitTest2() {
        Date now = Date.today();
        Date yesterdayDate = now.adddays(-1);
        
        Daily_Report__c dr1 = new Daily_Report__c(
            Reported_Date__c = Date.today(),
            Status__c = '作成中',
            Reporter__c = Userinfo.getUserId()
        );
        insert dr1;
        
        Event e = new Event(
            StartDateTime = Datetime.newInstance(yesterdayDate.year(), yesterdayDate.month(), yesterdayDate.day(), 9, 0, 0),
            EndDateTime = Datetime.newInstance(yesterdayDate.year(), yesterdayDate.month(), yesterdayDate.day(), 10, 0, 0)
        );
        insert e;
        
        Event__c ec1 = new Event__c(
            Daily_Report__c = dr1.Id,
            StartDateTime__c = Datetime.newInstance(now.year(), now.month(), now.day(), 10, 0, 0),
            EndDateTime__c = Datetime.newInstance(now.year(), now.month(), now.day(), 11, 0, 0),
            SyncCreatedDate__c = yesterdayDate,
            ActivityDate__c = now,
            Subject__c = 'event1',
            nextPlanDate__c = now,
            nextPlanTimePurpose__c = '10,10,12,10,test123,123',
            Event_ID__c = e.Id
        );
        insert ec1;
        
        List<Event> eList = [select id,Subject from Event where NextEventC_ID__c = :ec1.id];
        System.assertEquals('test123,123', eList[0].Subject);
        
        ec1.nextPlanTimePurpose__c = '10,10,12,10,test333,444';
        update ec1;
        
        List<Event> eList1 = [select id,Subject from Event where NextEventC_ID__c = :ec1.id];
        System.assertEquals('test333,444', eList1[0].Subject);
        
        delete ec1;
        
        List<Event> eList2 = [select id,Subject from Event where id = :e.id];
        System.assertEquals(0, eList2.size());
    }
}