@isTest
private class SIUploadFileTest {
	
	@isTest static void test_method_one() {
		// Implement test code
				// Implement test code
		Profile pf = [select Id from Profile where Id =:system.label.ProfileId_SystemAdmin];
	 	RecordType rtHP = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'HP'];
        RecordType rtDepClass = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_Class_ENT'];           // 耳鼻喉科
        RecordType rtDep = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_ENT'];
        RecordType rtDoc = [select id from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName =:'Doctor'];
        
		// 用户数据
		Account myAccount1 = new Account(Name='Testaccount002',view_product__c='Test01,Test02',Dealer_discount__c =20,RecordTypeId = rtHP.Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount1;
        Account myAccount2 = new Account(Name='Testaccount002',view_product__c='Test01,Test02',Department_Class_Label__c='耳鼻喉科',ParentId=myAccount1.Id,Dealer_discount__c =20,RecordTypeId = rtDepClass.Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount2;
        Account myAccount3 = new Account(Name='Testaccount002',view_product__c='Test01,Test02',Department_Class__c = myAccount2.Id,Hospital__c=myAccount1.Id,ParentId=myAccount2.Id,Dealer_discount__c =20,RecordTypeId = rtDep.Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount3;

        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount3.id);
        insert core;
        user myUser_Test = New User(Alias = 'newUTest',Email='newuser@testorg.com.CN',EmailEncodingKey='UTF-8', LastName='TestUser1', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = pf.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com.cn.test');
        insert myUser_Test;
		// 制作询价数据
		
	 	Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
	// 病院を作る
        Account hospital = new Account();
       
        String rid = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.recordtypeId = rid;
        hospital.Is_Active__c = '有効';
        insert hospital;

        Account accHP = new Account();
        accHP.Name = '病院1';
        accHP.Grade__c = '一般';
        accHP.OCM_Category__c = '一般';
        accHP.Attribute_Type__c = '保険省';
        accHP.Speciality_Type__c = '総合病院';
        accHP.Is_Active__c = '有効';
        accHP.State_Master__c = al.id;
        accHP.City_Master__c = al2.id;
        accHP.RecordTypeId = rid;
        accHP.Valid_To__c = Date.today() + 2;
        insert accHP;
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        Account accDepClass = new Account();
        accDepClass.Name = '戦略科室分類1';
        accDepClass.Department_Class_Label__c = '耳鼻喉科';
        accDepClass.Hospital_Department_Class__c = accHP.id;
        accDepClass.ParentId = accHP.id;
        accDepClass.RecordTypeId = rtDepClass.id;
        insert accDepClass;
        Account accDep = new Account();
        accDep.Name = '診療科1';
        accDep.Department_Class_Label__c = '診療科1';
        accDep.Hospital__c = accHP.id;
        accDep.ParentId = accDepClass.id;
        accDep.Department_Class__c = accDepClass.id;
        accDep.Department_Name__c = '診療科1';
        accDep.CurrencyIsoCode = 'CNY';
        accDep.RecordTypeId = rtDep.id;
        insert accDep;
        List<Contact> conList = new List<Contact>();
        Contact con1 = new Contact();
        con1.Firstname='ZZ1';
        con1.LastName = '取引先責任者1';
        con1.RecordTypeId = rtDoc.id;
        con1.AccountId = accDep.Id;
        conList.add(con1);

        insert conList;
        
        
    RecordType Type = [select id from RecordType where DeveloperName='SI_Oppor'];
    String TypeID = Type.Id;
    Opportunity opp1 = new Opportunity();
        opp1.Name = '引合1';
        opp1.AccountId = accDep.Id;
        opp1.Opportunity_Category__c = 'ENT';
        opp1.Trade__c = '外貿';
        opp1.StageName = '引合';
        opp1.CurrencyIsoCode = 'CNY';
        opp1.Close_Forecasted_Date__c = date.today().addMonths(1);
        opp1.CloseDate = date.today().addMonths(1);
        opp1.Competitor__c = 'B';
        opp1.Purchase_Type__c ='SI（手術室案件）';
        opp1.Sales_Root__c = 'OCM直接販売';
        opp1.Hospital__c = accHP.id;
        //opp1.Department_Class__c = accDepClass.id;
        opp1.StageName = '引合';
        opp1.RecordTypeid = TypeID;
    insert opp1;
		SI_Attachment__c newSac = new SI_Attachment__c();
		newSac.Opportunity_ID__c = opp1.id;
		newSac.Type__c = '项目方案书';
		newSac.Name__c = '*';
		IS_Opportunity_Demand__c iso = new IS_Opportunity_Demand__c();
		iso.name='*';
		iso.Public_Hospital_TF__c = true;
		iso.Preparation_Stage_TF__c = true;
		iso.Opportunity_ID__c = opp1.id;
		insert newSac;
		SI_Attachment__c UpSac =  [select id,Content__c from SI_Attachment__c where id = :newSac.id];
		UpSac.Content__c = '123123';
		update UpSac;
	}
	
	@isTest static void test_method_two() {
		// Implement test code
	}
	
}