@isTest
private class InquiryFormHandlerTest {

    @isTest static void test_method_one() {

        Inquiry_form__c inquiryform = new Inquiry_form__c();
        inquiryform.Name = '2019102101';
        inquiryform.Request1__c = '需要报价';
        inquiryform.Product1__c = '超声';
        insert inquiryform;
        
    }
  //   @isTest static void test_method_two() {
  //     //医院
  //     List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
  //       if (rectHp.size() == 0) {
  //           return;
  //       }
  //       //科室
  //       List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
  //       if (rectDpt.size() == 0) {
  //           return;
  //       }

        
    // Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

    // User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
  //     insert hpOwner;
  //     User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
  //     insert hpOwner2;



  //     Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
  //       hp.FSE_GI_Main_Leader__c = hpOwner.Id;
  //       hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
  //       insert hp;

  //       //战略科室
  //       Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];

  //       Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
  //       dpt.Name         = '*';
  //       dpt.Department_Name__c  = 'TestDepart';
  //       dpt.ParentId            = dc.Id;
  //       dpt.Department_Class__c = dc.Id;
  //       dpt.Hospital__c         = hp.Id;
  //       insert dpt;

  //       Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
  //       dpt1.Name         = '*';
  //       dpt1.Department_Name__c  = 'TestDepart1';
  //       dpt1.ParentId            = dc.Id;
  //       dpt1.Department_Class__c = dc.Id;
  //       dpt1.Hospital__c         = hp.Id;
  //       insert dpt1;

  //       Contact contact2 = new Contact();
  //       contact2.AccountId = dpt1.Id;
  //       contact2.FirstName = '責任者';
  //       contact2.LastName = 'test1经销商';
  //       insert contact2;

  //       Inquiry_form__c inquiryform = new Inquiry_form__c();
  //       inquiryform.Name = '2019102101';
  //       inquiryform.Hospital_Name__c = dpt1.Id;
  //       inquiryform.Status__c ='01.未跟进';
  //       inquiryform.Family_Name__c ='靳';
  //       inquiryform.Opportunity_Division__c = '询价';
  //       inquiryform.Contact_Name__c = contact2.Id;
  //       inquiryform.Reasons_options__c  ='客户无意向';
  //       inquiryform.Phone__c = '13844756322';
  //       inquiryform.Product1__c = '超声';
  //       inquiryform.Request1__c = '需要报价';
       
  //       insert inquiryform;

  //       List<Inquiry_form__c> info= [select id,Hospital_Name__c,Contact_Name__c,Department_Class__c,Hospital__c,Hospital__r.Name,OwnerId from Inquiry_form__c where id =: inquiryform.Id];
  //       System.assertEquals(hp.Id, info[0].Hospital_Name__c);
  //       System.assertEquals('hp-超声', info[0].Name);
  //   }
    @isTest static void test_method_three() {
        //医院
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        //科室
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }

        
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;



        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;

        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];

        Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;

        Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;

        Contact contact2 = new Contact();
        contact2.AccountId = dpt1.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;

        Inquiry_form__c inquiryform = new Inquiry_form__c();
        inquiryform.Name = '2019102101';
        inquiryform.Hospital_Name__c = dpt1.Id;
        inquiryform.Status__c ='01.未跟进';
        inquiryform.Family_Name__c ='靳';
        inquiryform.Opportunity_Division__c = '询价';
        //inquiryform.Contact_Name__c = contact2.Id;
        inquiryform.Reasons_options__c  ='客户无意向';
        inquiryform.Phone__c = '13844756322';
        inquiryform.Product1__c = '超声';
        inquiryform.Request1__c = '需要报价';
        insert inquiryform;

        Inquiry_form__c inquiryform0 = new Inquiry_form__c(Id = inquiryform.id);
        inquiryform0.Hospital_Name__c = null;
        //System.runAs (inquiryform){
            update inquiryform0;
        //}

    }
  //    static testMethod void testBeforeUpdate() {
  //      //医院
  //     List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
  //       if (rectHp.size() == 0) {
  //           return;
  //       }
  //       //科室
  //       List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
  //       if (rectDpt.size() == 0) {
  //           return;
  //       }

        
    // Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

    // User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
  //     insert hpOwner;
  //     User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
  //     insert hpOwner2;



  //     Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
  //       hp.FSE_GI_Main_Leader__c = hpOwner.Id;
  //       hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
  //       insert hp;

  //       //战略科室
  //       Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];

  //       Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
  //       dpt.Name         = '*';
  //       dpt.Department_Name__c  = 'TestDepart';
  //       dpt.ParentId            = dc.Id;
  //       dpt.Department_Class__c = dc.Id;
  //       dpt.Hospital__c         = hp.Id;
  //       insert dpt;

  //       Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
  //       dpt1.Name         = '*';
  //       dpt1.Department_Name__c  = 'TestDepart1';
  //       dpt1.ParentId            = dc.Id;
  //       dpt1.Department_Class__c = dc.Id;
  //       dpt1.Hospital__c         = hp.Id;
  //       insert dpt1;

  //       Contact contact2 = new Contact();
  //       contact2.AccountId = dpt1.Id;
  //       contact2.FirstName = '責任者';
  //       contact2.LastName = 'test1经销商';
  //       insert contact2;

  //       Inquiry_form__c inquiryform = new Inquiry_form__c();
  //       // inquiryform.Name = '2019102101';
  //       inquiryform.Hospital_Name__c = dpt1.Id;
  //       List<Account> dpecList = [select Id,Department_Class__c from Account where Id =: dpt1.Id];
  //       inquiryform.Department_Class__c = dpecList[0].Department_Class__c;
  //       inquiryform.Status__c ='01.未跟进';
  //       inquiryform.Company__c ='北京某某某测试公司';
  //       inquiryform.Family_Name__c ='靳';
  //       inquiryform.Opportunity_Division__c = '询价';
  //       inquiryform.Contact_Name__c = contact2.Id;
  //       inquiryform.Reasons_options__c  ='客户无意向';
  //       inquiryform.Phone__c = '13844756322';
  //       inquiryform.Product1__c = '超声';
  //       inquiryform.Request1__c = '需要报价';
  //       Test.startTest();
  //       insert inquiryform;
  //       ////.客户人员名前を変更する
  //       inquiryform.Phone__c = '16444756322';
  //       try {
  //           update inquiryform;
  //       } catch (Exception e) {

  //       }
        
  //       Test.stopTest();
  //    }
     // static testMethod void TestshareToOSCM(){
     //   List<Inquiry_form__c> tList = [SELECT Name, Id
     //            FROM Inquiry_form__c ORDER BY Id LIMIT 1];

     //    List<Inquiry_form__Share> tsList = [SELECT Id
     //            FROM Inquiry_form__Share WHERE ParentId = :tList AND RowCause = 'Manual'];
      

     //    Test.startTest();
     //    Delete tList[0];
     //    Test.stopTest();
     //    tsList = [SELECT Id
     //            FROM Inquiry_form__Share WHERE ParentId = :tList AND RowCause = 'Manual'];
     //    System.assertEquals(1, tsList.size());

     //    UnDelete tList[0];
     //    tsList = [SELECT Id
     //            FROM Inquiry_form__Share WHERE ParentId = :tList AND RowCause = 'Manual'];
     //    System.assertEquals(1, tsList.size());
     // }
}