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
@isTest
private class MonthlyVisitBatch1Tset {
 
    @IsTest
    static void TestMethod01() {
 
        Opportunity opp = new Opportunity();
        opp.Name = 'aiueo';
        opp.StageName = 'contact';
        opp.CloseDate = Date.today();
        insert opp;
 
        List<String> str = new List<String>();
        str.add(opp.Id);
 
        Datetime dt = DateTime.now().addDays(-4);
        Date dtDate = System.today().addDays(-4);
 
        Daily_Report__c dr = new Daily_Report__c();
        dr.reported_date__c = dtDate;
        dr.Status__c = '申請中';
        dr.Reporter__c = Userinfo.getUserId();
        insert dr;
 
        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        RecordType rtDoc = [select id from RecordType where IsActive = true and DeveloperName =:'Doctor'];
 
        Account acc = new Account();
        acc.RecordTypeId = rectCo.Id;
        acc.Name = '病院テスト1';
        insert acc;
 
        Contact con = new Contact();
        con.Doctor_Division1__c = '院长';
        con.LastName = 'yuanzhang';
        con.RecordTypeId = rtDoc.id;
        con.AccountId = acc.Id;
        Contact con2 = new Contact();
        con2.Doctor_Division1__c = '副主任';
        con2.LastName = 'zhuren';
        con2.RecordTypeId = rtDoc.id;
        con2.AccountId = acc.Id;
        insert new Contact[] {con, con2};
 
        Event__c ec = new Event__c();
        ec.Daily_Report__c = dr.Id;
        ec.StartDateTime__c = System.now();
        ec.EndDateTime__c = System.now();
        ec.Subject__c = 'Subject';
        ec.Location__c = 'Location';
        ec.ActivityDate__c = dr.reported_date__c;
        ec.Visitor1_ID__c = con.Id;
        ec.Visitor2_ID__c = con2.Id;
        insert ec;
 
        Event_Oppotunity__c eo = new Event_Oppotunity__c();
        eo.Opportunity__c = opp.Id;
        eo.End_Time__c = dt;
        eo.Daily_Report__c = dr.Id;
        eo.EventC_ID__c = ec.Id;
        insert eo;
 
        Test.StartTest();
        Database.executeBatch( new MonthlyVisitBatch1(),100);
        Database.executeBatch( new MonthlyVisitBatch1(str),100);
        Test.stopTest();
    }
 
}