@isTest
private class CertificationDetailTriggerTest {
    public static Account acc0;
    public static License_Information__c licenseInfo;
    public static String effectiveYear;
    static void inittransfersData() {
        NFMUtil.EscapeSBG001TriggerHandler = true;
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        // ANI代理商
        acc0 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer ANI',
            FacilityName__c = 'abc',
            DivisionName_D__c = 'Customer ANI',
            FacilityNameD__c = 'abc',
            PostCode__c = '123456',
            NationalEnterpriseUser__c = true
        );
        insert acc0;
        // 辐射证照
        licenseInfo = new License_Information__c();
        licenseInfo.LicenseAndAccount__c = acc0.Id;
        licenseInfo.ValidFrom__c = Date.today().addDays(-22);
        licenseInfo.ValidTo__c = Date.today().addDays(22);
        licenseInfo.LicenseType__c = '辐射安全许可证';
        insert licenseInfo;
        // 创建购买明细
        effectiveYear = String.valueOf(Date.today().year());
        PurchaseDetails__c pdetail = new PurchaseDetails__c();
        pdetail.PurchaseAccount__c = acc0.Id;
        pdetail.TakeEffectInYear__c = effectiveYear;
        pdetail.PurProductModel__c = 'Delta';
        pdetail.SoldNumber__c = 22;
        // insert pdetail;

        PurchaseDetails__c pdetai2 = new PurchaseDetails__c();
        pdetai2.PurchaseAccount__c = acc0.Id;
        pdetai2.TakeEffectInYear__c = effectiveYear;
        pdetai2.PurProductModel__c = 'Vanta';
        pdetai2.SoldNumber__c = 22;
        // insert pdetai2;

        PurchaseDetails__c pdetai3 = new PurchaseDetails__c();
        pdetai3.PurchaseAccount__c = acc0.Id;
        pdetai3.TakeEffectInYear__c = effectiveYear;
        pdetai3.PurProductModel__c = 'FOX-IQ';
        pdetai3.SoldNumber__c = 22;
        // insert pdetai3;

        insert new List<PurchaseDetails__c> {pdetail,pdetai2,pdetai3};
    }
    static testMethod void testMethod1() {
        inittransfersData();
        String accountId = acc0.Id;
        // 新建证照明细
        CertificationDetails__c cDetail = new CertificationDetails__c();
        cDetail.LicenseInformation__c = licenseInfo.Id;
        cDetail.DeviceName__c = '手持式X荧光分析仪';
        cDetail.ActivitieTypes__c = '销售';
        cDetail.ProdustionType__c = 'Delta和Vanta';
        cDetail.ProductModelNumber__c = 122;

        CertificationDetails__c cDetai2 = new CertificationDetails__c();
        cDetai2.LicenseInformation__c = licenseInfo.Id;
        cDetai2.DeviceName__c = '测试';
        cDetai2.ActivitieTypes__c = '销售';
        cDetai2.ProdustionType__c = 'FOX-IQ';
        cDetai2.ProductModelNumber__c = 122;

        insert new List<CertificationDetails__c> {cDetail,cDetai2};

        // List<PurchaseDetails__c> purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
        //                          PurProductModel__c, PurchaseAccount__c,PurchaseDetail__c
        //                          from PurchaseDetails__c
        //                          where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId];

        // System.assertEquals(depart1.Id, purchaseDetailsList);
    }
}