@isTest
private class Event_ConfirmationTest {
    
    private static Event e{get;set;}
    private static User u1{get;set;}
    private static User u2{get;set;}
    private static User u3{get;set;}
    private static User u4{get;set;}
    
    /**
     * 初期処理.
     */
    private static void init() {
        Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        
        u1 = new User(Test_staff__c = true);
        u1.LastName = '_サンブリッジ';
        u1.FirstName = 'あ';
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest01@sunbridge.com';
        u1.CommunityNickname = 'olympusTest01@sunbridge.com';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        u1.Post__c = '部长';
        insert u1;
        
        u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'あ';
        u2.Alias = 'あ';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com';
        u2.CommunityNickname = 'olympusTest02@sunbridge.com';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = p.id;
        u2.Job_Category__c = '销售服务';
        u2.Province__c = '東京';
        u2.Post__c = '经理';
        insert u2;
        
        u3 = new User(Test_staff__c = true);
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'あ';
        u3.Alias = 'あ';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'olympusTest03@sunbridge.com';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = p.id;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '東京';
        u3.Post__c = '';
        insert u3;
        
        u4 = new User(Test_staff__c = true);
        u4.LastName = '_サンブリッジ';
        u4.FirstName = 'あ';
        u4.Alias = 'あ';
        u4.Email = 'olympusTest04@sunbridge.com';
        u4.Username = 'olympusTest04@sunbridge.com';
        u4.CommunityNickname = 'olympusTest04@sunbridge.com';
        u4.IsActive = true;
        u4.EmailEncodingKey = 'ISO-2022-JP';
        u4.TimeZoneSidKey = 'Asia/Tokyo';
        u4.LocaleSidKey = 'ja_JP';
        u4.LanguageLocaleKey = 'ja';
        u4.ProfileId = p.id;
        u4.Job_Category__c = '销售服务';
        u4.Province__c = '東京';
        u4.Post__c = '副总监';
        insert u4;
        
        e = new Event();
        e.StartDateTime = datetime.now();
        e.EndDateTime = datetime.now();
        e.DurationInMinutes = 0;
        insert e;
    }
    
    static testMethod void myUnitTest() {
        init();
        
        List<ID> idList = new List<ID>();
        idList.add(e.id);
        System.runAs(u1) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u2) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u3) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u4) {
            Event_Confirmation.checkMinister(idList);
        }
    }
    
    static testMethod void checkMinisterTest() {
        init();
        
        Date t = Date.today();
        Date t1 = t.addMonths(6);
        
        Daily_Report__c dr1 = new Daily_Report__c(
            Reported_Date__c = t1,
            Status__c = '作成中',
            Reporter__c = Userinfo.getUserId()
        );
        
        insert dr1;
        
        Event__c ec1 = new Event__c(
            Daily_Report__c = dr1.Id,
            StartDateTime__c = Datetime.newInstance(t1.year(), t1.month(), t1.day(), 10, 0, 0),
            EndDateTime__c = Datetime.newInstance(t1.year(), t1.month(), t1.day(), 11, 0, 0),
            ActivityDate__c = dr1.Reported_Date__c,
            Subject__c = 'eventc1'
        );
        insert ec1;
        
        List<ID> idList = new List<ID>();
        idList.add(ec1.id);
        
        Event_Confirmation.checkMinister(idList);
        
        System.runAs(u1) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u2) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u3) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u4) {
            Event_Confirmation.checkMinister(idList);
        }
    }
}